Cod sursa(job #2417311)
Utilizator | Data | 29 aprilie 2019 15:00:55 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int MOD = 1999999973;
long long lgput(int n,int p)
{
long long rasp=1;
while(p!=0)
{
if(p%2==1){
rasp=(1LL*rasp*n)%MOD;
p--;
}
else{
n=(1LL*n*n)%MOD;
p/=2;
}
}
return rasp;
}
int main()
{
int n,p;
fin >> n >> p;
fout << lgput(n,p);
return 0;
}