Cod sursa(job #2869708)
Utilizator | Data | 11 martie 2022 19:37:17 | |
---|---|---|---|
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>
#define P 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long LogP(int n, int p)
{
long long rez = 1;
while (p > 0)
{
if (p % 2 == 1)
rez = 1LL * n * rez % P;
p /= 2;
n = 1LL * n * n % P;
}
return rez;
}
int main()
{
long long n, p;
fin >> n >> p;
fout << LogP(n, p) << "\n";
fin.close();
fout.close();
return 0;
}