Cod sursa(job #641225)
| Utilizator | Data | 27 noiembrie 2011 16:25:47 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.38 kb |
#include<stdio.h>
#define q 1999999973
long power(long x , long n){
long buff;
if(n == 0)
return 1;
buff = power(x, n/2)%q;
if(n%2)
return ((x%q)*(buff*buff)%q)%q;
else
return (buff*buff)%q;
}
int main(){
long N, P;
freopen("lgput.in","r",stdin);
freopen("lgput.out", "w", stdout);
scanf("%ld %ld",&N, &P);
printf("%ld", power(N, P));
return 0;
}