Cod sursa(job #2642910)
Utilizator | Data | 17 august 2020 17:55:58 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
using namespace std;
int main()
{
ifstream cin("lgput.in");
ofstream cout("lgput.out");
unsigned long long n, p, x, prefix = 1, mod = 1999999973;
cin>> n;
cin>>p;
x = n;
while(p!=1){
if(p%2){
prefix*=x%mod;
x = (x*x)%mod;
}
else{
x = (x*x)%mod;
}
p/=2;
}
cout<<(x*prefix)%mod;
}