Cod sursa(job #3135169)
Utilizator | Data | 2 iunie 2023 02:51:43 | |
---|---|---|---|
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;
const int nr = 1999999973;
long long lgcalc(long long x, long long n)
{
if (n == 0)
return 1;
if (n % 2 == 0)
return lgcalc(x * x % nr, n / 2) % nr;
else
return (x * lgcalc(x * x % nr, (n - 1) / 2)) % nr;
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long N, P;
fin >> N >> P;
long long rz = lgcalc(N, P);
fout << rz;
return 0;
}