Cod sursa(job #1416286)
| Utilizator | Data | 7 aprilie 2015 20:27:59 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <cstdio>
#define MODULO 1999999973
using namespace std;
long long ridiclaputere(long long f, int exp)
{
long long rez=1;
while(exp)
{
if(exp%2==0)
{
f*=f;
f%=MODULO;
exp/=2;
}
else
{
rez*=f;
rez%=MODULO;
exp--;
}
}
return rez;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
long long n;
int p;
scanf("%lld%d", &n,&p);
printf("%lld", ridiclaputere(n,p));
return 0;
}
