Cod sursa(job #1752604)
| Utilizator | Data | 4 septembrie 2016 17:03:25 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
#include <cmath>
#define MOD 1999999973
using namespace std;
long long rest(long long N, long long P)
{
long long a;
if(P==1)
{
return N;
}
if(P%2==0)
{
a=rest(N,P/2);
a=(a*a)%MOD;
return a;
}
else
{
a=rest(N,P-1);
a=(a*N)%MOD;
return a;
}
}
int main()
{
long long N,P;
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld",&N,&P);
printf("%lld",rest(N,P));
}
