Cod sursa(job #2023221)
Utilizator | Data | 18 septembrie 2017 16:27:23 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long lgput(long long x, long long p)
{
long long n = 1;
while(p > 0)
{
if(p % 2 != 0)
{
n *= x;
p--;
}
x = x * x;
p /= 2;
}
return n % 1999999973;
}
int main()
{
long long x, p;
fin >> x >> p;
fout << lgput(x, p);
return 0;
}