Cod sursa(job #1583462)
Utilizator | Data | 28 ianuarie 2016 23:20:33 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <math.h>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
void lgput()
{
long long N,P,rest=1;
fin>>N>>P;
while(P>0)
{
if(P%2==1)
{
rest=(rest*N)%1999999973;
--P;
}
P/=2;
N=(N*N)%1999999973;
}
fout<<rest;}
int main()
{
lgput();
fin.close();
fout.close();
return 0;
}