Cod sursa(job #2127865)
Utilizator | Data | 11 februarie 2018 10:11:02 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.64 kb |
#include <cstdio>
using namespace std;
const int MOD = 1999999973;
long long powx(long long a, long long b){
int rez = 1;
while(b > 1){
if(b % 2 == 0){
a = a * a;
a %= MOD;
b /= 2;
}
else{
a = a * a;
rez *= a;
b /= 2;
a %= MOD;
rez %= MOD;
}
}
return (a * rez) % MOD;
}
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
long long a, b;
scanf("%lld %lld", &a, &b);
printf("%lld", powx(a, b));
return 0;
}