Cod sursa(job #356835)
Utilizator | Data | 16 octombrie 2009 19:54:00 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.26 kb |
#include<stdio.h>
long long N,P,S,M;
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld%lld",&N,&P);
M=1999999973;
S=1;
while(P)
{
if(P%2)
S=(S*N)%M;
N=(N*N)%M;
P/=2;
}
printf("%lld\n",S);
}