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