Cod sursa(job #1082175)
Utilizator | Data | 14 ianuarie 2014 11:53:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <cstdio>
#define MOD 1999999973
using namespace std;
long long a,n,p;
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld%lld",&a,&n);
p=1;
while(n>0)
{
if(n%2==1)
{
p=p*a;
p%=MOD;
--n;
}
else
{
a=a*a;
a%=MOD;
n=n/2;
}
}
printf("%lld\n",p);
return 0;
}