Cod sursa(job #256685)
| Utilizator | Data | 11 februarie 2009 23:55:20 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include<stdio.h>
#define md 1999999973
long pow(long x, long n)
{
long result = 1;
while ( n ) {
if ( n & 1 ) {
result =(result%md * x%md)%md;
}
x =(x%md * x%md)%md;
n /= 2;
}
return result;
}
int main()
{
long a,b;
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%ld %ld",&a,&b);
printf("%i",pow(a,b));
return 0;
}
