Cod sursa(job #624165)
Utilizator | Dumitru Andrei Georgian Schumi | Data | 21 octombrie 2011 21:32:06 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <cstdio>
using namespace std;
const int mod = 1999999973;
long long power(int x, int y)
{
if(y == 1)
return x;
if(y % 2 == 0) {
long long a = power(x, y / 2);
return (a * a) % mod;
}
if(y % 2 != 0) {
long long a = power(x,y-1);
return (a * x) % mod;
}
}
int main()
{
int a, b;
freopen ("lgput.in","r",stdin);
freopen ("lgput.out", "w", stdout);
scanf ("%d %d", &a, &b);
printf("%lld", power(a, b));
return 0;
}