Cod sursa(job #688901)
| Utilizator | Data | 23 februarie 2012 22:29:30 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include <cstdio>
#define M 1999999973
#define LL long long
using namespace std;
int a, b;
LL lgput(LL a , LL b){
LL p = 1;
while ( b > 1 ){
if ( b % 2 == 1 ) p = ( p * a ) % M;
a = ( a * a ) % M;
b = b / 2;
}
return ( a * p ) % M;
}
int main(){
freopen("lgput.in","r",stdin); freopen("lgput.out","w",stdout);
scanf("%d%d", &a, &b);
printf("%lld\n", lgput(a,b));
return 0;
}
