Cod sursa(job #3003614)
Utilizator | Data | 15 martie 2023 20:19:59 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
#define NR 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n, p;
long long exp(int a, int b)
{
if (b == 0)
return 1;
long long p1 = exp(a, b / 2) % NR;
if (b % 2 == 0)
return p1 * p1 % NR;
return a * p1 * p1 % NR;
}
int main()
{
fin >> n >> p;
fout << exp(n, p) % NR;
return 0;
}