Cod sursa(job #2147122)
Utilizator | Data | 28 februarie 2018 14:46:54 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int main()
{
int n,p = 1,x;
in >> x >> n;
while (n != 0)
{
if (n%2 == 0)
{
x = (x%1999999973 * x%1999999973)%1999999973;
n /= 2;
}
else
{
p = (p%1999999973 * x%1999999973)%1999999973;
n--;
}
}
out << p;
return 0;
}