Cod sursa(job #3135163)
| Utilizator | Data | 2 iunie 2023 02:30:17 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int nr = 1999999973;
long long lgcalc(long long x, long long int n)
{
if (n == 0)
return 1;
if (n % 2)
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;
}
