Cod sursa(job #2310534)
Utilizator | Data | 1 ianuarie 2019 05:47:41 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<iostream>
#include<fstream>
#define MOD 1999999973
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
int main ()
{
long long int x, n;
long long int p;
fin >> x >> n;
p = 1;
while (n > 0)
{
if (n % 2 == 0)
{
n = n/2;
x = (x*x) % MOD;
}
else
{
p = (p*x) % MOD;
n = n-1;
}
}
fout << p << endl;
return 0;
}