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