Cod sursa(job #1292166)
| Utilizator | Data | 13 decembrie 2014 19:21:52 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <cstdio>
#define ll long long
#define mod 1999999973
using namespace std;
ll n,p;
ll log_exp(ll a,ll b){
ll x = 1,e = 0,s = a;
while((1<<e) <= b){
if(((1<<e) & b) != 0){
x = (x * s) % mod;
}
s = (s*s)%mod;
e++;
}
return x;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld ",&n,&p);
printf("%lld\n",log_exp(n,p));
return 0;
}
