Cod sursa(job #375061)
Utilizator | Data | 19 decembrie 2009 12:25:28 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <stdio.h>
#include <string.h>
const int n_max = 10001;
const int m = 1999999973;
int main()
{
unsigned int i, n, p;
long long a, sol = 1;
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d %d", &n, &p);
a = n;
for (i = 0; (1<<i) <= p; ++ i)
{
if ( (1<<i) & p)
sol= (sol * a) % m;
a=(a * a) % m;
}
printf("%lld\n", sol);
}