Cod sursa(job #146974)
Utilizator | Data | 2 martie 2008 14:27:45 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <stdio.h>
const long long modul = (long long) 1999999973;
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
long long sol = 1, temp, n, p;
scanf("%lld %lld", &n, &p);
temp = n;
for(int i = 0; (long long) 1 << i <= p; ++i)
{
if((long long) 1 << i & p)
{
sol *= temp;
sol %= modul;
}
temp *= temp;
temp %= modul;
}
printf("%lld\n", sol);
return 0;
}