Cod sursa(job #624206)
Utilizator | Data | 21 octombrie 2011 23:48:51 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <cstdio>
int pow(int a, int b)
{
if (!b) return 1;
int sq = a*a % 1999999973;
if ( b%2 )
return pow( sq, b/2 );
else
return a*pow( sq, (b-1)/2 ) % 1999999973;
}
int main()
{
int x, y, z;
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d%d", &x, &y);
z = pow(x, y);
printf("%d", z);
}