Cod sursa(job #386807)
Utilizator | Data | 26 ianuarie 2010 04:45:47 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<stdio.h>
#define modulo 1999999973
int n,p,x[100],k,put,a;
void baza(int a)
{
while(a)
{
k++;
x[k]=a%2;
a/=2;
}
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d%d",&n,&p);
baza(p);
put=1;a=n;
while(k)
{
if(x[k])put=(put*a)%modulo;
a=(a*a)%modulo;
k--;
}
printf("%d",put);
return 0;
}