Cod sursa(job #2446016)
Utilizator | Data | 6 august 2019 18:41:25 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int NR= 1999999973;
int NlaP(int N,int P){
int r=1;
while(P){
if(P % 2 == 1)
r=(1LL * r * N)%NR;
N =(1LL * N * N)%NR;
P=P/2;
}
return r;
}
int main(){
int N,P;
fin >> N >> P;
fout<<NlaP(N,P);
}