Cod sursa(job #2943684)
Utilizator | Data | 21 noiembrie 2022 15:36:28 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int M=1999999973;
int putere(int a,int n){
int p=1,cifb;
while(n){
cifb=n%2;
if(cifb>0) p=(long long)p*a%M;
a=(long long)a*a%M;
n/=2;
}
return p;
}
int main(){
int n,p;
fin>>n>>p;
fout<<putere(n,p);
fin.close();
fout.close();
return 0;
}