Cod sursa(job #274610)
| Utilizator | Data | 9 martie 2009 21:20:05 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <stdio.h>
#define Mod 1999999973
int a,b;
int power(int a, int b)
{
int x;
if (b==1) return a;
else
if (b%2==0)
{
x=power(a,b/2);
return (x*x)%Mod;
}
else
{
x=power(a,b/2);
return (((x*x)%Mod)*a)%Mod;
}
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d %d", &a,&b);
printf("%d", power(a,b));
return 0;
}