Cod sursa(job #1809765)
| Utilizator | Data | 19 noiembrie 2016 11:20:43 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long putere(long long a, long long b)
{
a %= 1999999973;
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;
}
