Cod sursa(job #3131602)
| Utilizator | Data | 20 mai 2023 18:01:04 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int recPow(unsigned int n, unsigned int p)
{
if (p < 0)
return recPow(1 / n, -p);
if (p == 0)
return 1;
if (p % 2 == 0)
return recPow(n * n, p / 2);
if (p % 2 == 1)
return n * recPow(n * n, p / 2);
}
int main()
{
float n;
int p;
int pow;
int x=1999999973;
in >> n >> p;
pow = recPow(n, p);
out << pow%x;
return 0;
}