Cod sursa(job #664624)
| Utilizator | Data | 20 ianuarie 2012 15:20:29 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <cstdio>
#define DN 1999999973
using namespace std;
unsigned long long nrf=1;
void f(int nr,int putere)
{
for(int i=1;i<=putere/2;i++)
nrf=(((nrf%DN)*nr*1LL)%DN*nr*1LL)%DN;
printf("%lld",nrf);
}
int main()
{
freopen("lgput.in","r", stdin);
freopen("lgput.out","w", stdout);
long long n,p;
scanf("%lld %lld",&n,&p);
if(p%2==0) f(n,p);
else
{
nrf*=n;
f(n,p-1);
}
return 0;
}
