Cod sursa(job #1698787)
| Utilizator | Data | 5 mai 2016 13:05:05 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include<fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
typedef unsigned long long DWORD64;
DWORD64 pow_mod(DWORD64 x, DWORD64 p, DWORD64 mod)
{
DWORD64 pr = 1LL;
while (p!=1)
{
if (p & 1)
pr = (pr*x) % mod, p--;
else
x = (x*x) % mod, p = p / 2;
}
return (pr * x) % mod;
}
int main()
{
DWORD64 x, p;
in >> x >> p;
out << pow_mod(x, p, 1999999973LL);
return 0;
}