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