Cod sursa(job #492624)
| Utilizator | Data | 15 octombrie 2010 12:59:43 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include<stdio.h>
int modulo(long a, long b, long c){
long aux;
if(b==0)
return 1;
if(b==1)
return b;
else
if(b%2==0){
aux=modulo(a, b/2, c);
return ((aux%c)*(aux%c))%c;
}
else{
aux=modulo(a, b-2, c);
return ((aux%c)*(aux%c)*(a%c))%c;
}
}
int main(){
freopen ("lgput.in", "r", stdin);
freopen ("lgput.out", "w", stdout);
long a, b, c;
scanf("%ld %ld %ld ", &a, &b);
//printf("%d %d %d ", a, b, c);
printf("%ld ", modulo (a, b, 1999999973));
return 0;
}
