Cod sursa(job #565701)
Utilizator | Vlad Schnakovszki shnako | Data | 28 martie 2011 10:33:33 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.33 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()
{
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;
}