Cod sursa(job #720164)
Utilizator | Mihai Ionut Enache Mihai22e | Data | 22 martie 2012 13:35:17 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include<stdio.h>
# define MOD 1999999973;
long long int n, p, r = 1;
void read()
{
FILE *f = fopen("lgput.in", "r");
fscanf(f, "%lld %lld", &n, &p);
fclose(f);
}
void solve()
{
int i;
for(i=0;(1<<i)<=p;i++)
{
if (1<<i & p)
r = (r * n) % MOD;
n = (n*n) % MOD;
}
}
void write()
{
FILE *g = fopen("lgput.out", "w");
fprintf(g, "%lld\n", r);
fclose(g);
}
int main()
{
read();
solve();
write();
return 0;
}