Cod sursa(job #1514028)
Utilizator | Data | 30 octombrie 2015 14:55:58 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in ("lgput.in");
ofstream out ("lgput.out");
int main()
{
long long n,p,rest=1;
in>>n>>p;
while (p!=1)
{
if (p%2==0)
{
p=p/2;
n=n*n;
n=n%1999999973;
}
else
{
p=p-1;
rest=rest*n;
rest=rest%1999999973;
}
}
out << (n*rest)% 1999999973;
return 0;
}