Cod sursa(job #1364395)
| Utilizator | Data | 27 februarie 2015 17:24:42 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <cstdio>
#define MOD 1999999973
using namespace std;
long long lg_put(long long a,long long b)
{
long long x1 = a,x2 = 1;
if(b == 0)
return 1;
if(b == 1)
return a;
while(b > 1)
if(b & 1){
x2 = ( x1 * x2 ) % MOD;
b ^= 1;
}
else{
x1 = (x1 * x1) % MOD;
b >>=1;
}
return (x1 * x2) % MOD;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
long long a,b;
scanf("%lld%lld",&a,&b);
printf("%lld\n",lg_put(a,b));
return 0;
}
