Cod sursa(job #1583490)
Utilizator | Data | 28 ianuarie 2016 23:50:56 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const long long rest = 1999999973LL;
long long n, p;
long long Sol;
int main()
{
f>>n>>p;
Sol = 1;
while(p > 1)
{
if(p%2 == 0)
Sol = (Sol*Sol) % rest, p = p/2;
else
Sol = (Sol*n) % rest, p--;
// p = p/2;
}
g<<Sol<<'\n';
return 0;
}