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