Cod sursa(job #1201949)
Utilizator | Data | 26 iunie 2014 15:07:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<stdio.h>
#define m 1999999973
using namespace std;
long long exp(long long x,long long n)
{
if(n==0) return 1;
if(n==1) return x;
if(n%2==0) return exp(x*x,n/2)%m;
if(n%2==1) return (x*exp(x*x,(n-1)/2))%m;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
long long n,p;
scanf("%lld %lld",&n,&p);
printf("%lld\n",exp(n,p));
return 0;
}