Cod sursa(job #235715)
| Utilizator | Data | 25 decembrie 2008 14:39:34 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <stdio.h>
#define ull unsigned long long
unsigned f(unsigned a,unsigned b)
{
if (b == 0) return 1;
if (b == 1) return (ull)a%1999999973;
if (b%2==1) return ((ull)a*f(a,b-1))%1999999973;
unsigned ret = (ull)f(a,b/2)%1999999973;
ret = ((ull)ret*ret)%1999999973;
return ret;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
int a,b;
scanf("%d%d",&a,&b);
printf("%u", f(a,b));
return 0;
}
