Cod sursa(job #2928597)
Utilizator | Data | 23 octombrie 2022 14:37:12 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
#define MOD 1999999973
void lgput(int nr, int pow, int &rez)
{
if(pow == 0)
{
rez = 1;
return;
}
lgput(nr * nr, pow / 2, rez);
if(pow % 2 == 1)
{
rez *= nr;
}
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int a, b, pow;
fin >> a >> b;
lgput(a, b, pow);
fout << pow;
return 0;
}