Cod sursa(job #565703)
Utilizator | Vlad Schnakovszki shnako | Data | 28 martie 2011 10:35:56 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include <cstdio>
#define IMP 1999999973
using namespace std;
FILE *f=fopen("lgput.in", "r"), *g=fopen("lgput.out", "w");
long long n, p, t;
int main()
{
t=1;
fscanf(f, "%lld%lld", &n, &p);
while (p)
{
if (p%2)
t=(t*n)%IMP;
n=(n*n)%IMP;
p/=2;
}
fprintf(g, "%lld", t);
fclose(f);
fclose(g);
return 0;
}