Cod sursa(job #1748206)
Utilizator | Data | 26 august 2016 11:32:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.57 kb |
#include<bits/stdc++.h>
#define MOD 1999999973
using namespace std;
int n,p,n1,nr,x,y;
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d%d",&n,&p);
n1=1;
nr=p;
while (nr)
{
if(!(nr%2))
{
x=n%MOD;
n=(x*x)%MOD;
nr>>=1;
}
else
{
x=n%MOD;
y=n1%MOD;
n1=(x*y)%MOD;
nr--;
}
}
n1=n1%MOD;
printf("%d\n",n1);
return 0;
}