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