Cod sursa(job #3167480)
Utilizator | Data | 10 noiembrie 2023 19:08:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
int main()
{
int n,p,L = 1999999973;
fin >> n >> p;
while (p>0){
if (p==0){
fout << 1;
break;
}
if (p==1) break;
if (p%2==0){
n *= n;
n = n%L;
p /= 2;
}else{
p += 1;
p /= 2;
n *= n;
n = n%L;
}
}
fout << n;
return 0;
}