Cod sursa(job #2060439)
Utilizator | Data | 8 noiembrie 2017 11:50:50 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{ long long n, p, sol = 1, w = 1999999973;
f >> n >> p;
while(p > 0)
{
if(p % 2 == 1) sol = (sol * n) % w;
n = (n * n) % w;
p = p / 2;
}
g << sol;
f.close();
g.close();
return 0;
}