Cod sursa(job #1809708)
| Utilizator | Data | 19 noiembrie 2016 10:43:29 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long putere(int a, int b)
{
if(b == 1)
{
return a;
}
if(b % 2 == 0)
{
return putere(a * a, b / 2);
}
else
{
return putere(a, (b - 1) / 2) * a;
}
}
int main()
{
long long a, b;
fin >> a >> b;
fout << putere(a, b) % 1999999973;
return 0;
}
