Cod sursa(job #3298604)
Utilizator | Data | 31 mai 2025 17:50:24 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#include <iostream>
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
uint64_t pow(uint32_t n, uint32_t p)
{
if (p == 0)
{
return 1;
}
if (p == 1)
{
return n;
}
if ((p & 1) == 1)
{
uint64_t N = pow(n, (p - 1) / 2);
return (n * N * N);
}
uint64_t N = pow(n, p / 2);
return (N * N);
}
int main()
{
uint32_t n, p;
fin >> n >> p;
uint32_t result = pow(n, p) % MOD;
fout << result << '\n';
return 0;
}