Cod sursa(job #2504210)
| Utilizator | Data | 4 decembrie 2019 17:16:01 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int exp(int x, int n)
{
if (n == 0) return 1;
else if (n % 2 == 0)
{
int y = exp(x, n / 2);
return y * y;
}
else
{
int z = exp(x, (n - 1) / 2);
return x * z * z;
}
}
int main()
{
int N,P;
const int MOD = 1999999973;
fin >> N >> P;
fout << exp(N, P);
}
