Cod sursa(job #1522023)
Utilizator | Data | 11 noiembrie 2015 08:38:36 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#define mod 1999999973
using namespace std;
long long expRap(long long a, long long b)
{
if (b == 0) return 1;
int aux = 1;
while (b > 1
)
{
if (b % 2 == 0)
{
a *= a % mod;
b /= 2;
}
else
{
aux *= a % mod;
b--;
}
}
return (a * aux) % mod;
}
int main()
{
long long n, p;
cin >> n >> p;
cout << expRap(n, p);
return 0;
}