Cod sursa(job #933607)
| Utilizator | Data | 30 martie 2013 11:12:36 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include<cstdio>
using namespace std;
FILE *in,*out;
const int NUL = 1999999973;
int putere(int a, int b){
if(b==1)
return a;
if(b%2==0)
return putere(a*a%NUL, b/2)%NUL;
if(b%2==1)
return a* putere(a*a%NUL, (b-1)/2) %NUL;
}
int main(){
in=fopen("lgput.in","r");
out=fopen("lgput.out","w");
int a,b;
fscanf(in,"%d%d",&a,&b);
int sol=putere(a,b);
fprintf(out,"%d",sol);
return 0;
}
