Cod sursa(job #3227501)
Utilizator | Data | 1 mai 2024 14:38:53 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
//https://infoarena.ro/problema/lgput
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long result=1;
#define Nmax 1999999973
int main(void)
{
long long n,p;
fin>>n>>p;
n=n%Nmax;
while(p)
{
if(p%2==1)
{
result=result*n%Nmax;
p=p-1;
}
else
{
n=n*n%Nmax;
p=p/2;
}
}
fout<<result;
return 0;
}