Cod sursa(job #2144564)
Utilizator | Data | 26 februarie 2018 20:10:18 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
#define modulo 1999999973
long long x,p;
int main()
{
f>>x>>p;
for (;p>1;)
{
int paritate=p&1;
if (paritate)
{
x*=((x*x)%modulo);
x%=modulo;
p=(p-1)/2;
}
else
{
x*=x;
x%=modulo;
p/=2;
}
}
g<<x;
return 0;
}