Cod sursa(job #3003634)
| Utilizator | Data | 15 martie 2023 20:32:06 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
#define NR 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n, p;
long long exp(long long a, long long 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;
}
