Cod sursa(job #1610962)
Utilizator | Data | 23 februarie 2016 20:53:38 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <stdio.h>
const int m = 1999999973;
int main()
{
FILE *f, *g;
unsigned int i, n, p;
long long a, sol = 1;
f = fopen("lgput.in", "r");
g = fopen("lgput.out", "w");
fscanf(f, "%d %d", &n, &p);
a = n;
for (i = 0; (1 << i) <= p; i++)
{
if ( ((1<<i) & p) > 0)
sol= (sol * a) % m;
a=(a * a) % m;
}
fprintf(g ,"%lld", sol);
return 0;
}