Cod sursa(job #1944053)
Utilizator | Data | 28 martie 2017 22:20:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int long long N,P,l;
int main()
{
fin>>N>>P;
if(N==0)fout<<0;
else if(N==1 || P==0)fout<<1;
else if(P==1)fout<<N;
else {
l=N*N;
if(P%2){
P-=1,P/=2;
while(P)l=(l*N)%1999999973,P--;
l=(l*N)%1999999973;
}else{
P/=2;
while(P)l=(l*N)%1999999973,P--;
}
fout<<l;
}
}