Cod sursa(job #624212)
Utilizator | Data | 21 octombrie 2011 23:56:27 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
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 (a*pow( sq, (b-1)/2 )) % 1999999973;
else
return pow( sq, b/2 );
}
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);
}