Cod sursa(job #3220593)
Utilizator | Data | 4 aprilie 2024 11:53:53 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include<fstream>
using namespace std;
ifstream f("lgput.in");
ofstream fout("lgput.out");
unsigned rp(unsigned n, unsigned p)
{
unsigned r = 1;
while (p) {
if (p % 2 == 1) {
r = (1LL * r * n) % 1999999973;
}
n = (1LL * n * n) % 1999999973;
p /= 2;
}
return r;
}
int main()
{
unsigned n, p;
f >> n >> p;
fout << rp(n, p);
return 0;
}