Cod sursa(job #1583496)
Utilizator | Data | 28 ianuarie 2016 23:54:02 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 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;
int Sol;
int main()
{
f>>n>>p;
Sol = 1;
while(p)
{
if(p%2 == 1) Sol = (Sol*n) % rest;
n = (n*n) % rest;
p = p/2;
}
g<<Sol<<'\n';
return 0;
}