Cod sursa(job #2323616)
Utilizator | Data | 19 ianuarie 2019 13:58:38 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
///Exponentiere in timp logaritmic
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin ("lgput.in");
ofstream fout("lgput.out");
long long a, b;
long long Ridicare(long long a, long long b)
{
if (b == 0)
return 1;
if (b == 1)
return a % 1999999973;
long long aux = Ridicare(a, b / 2);
aux = (aux * aux) % MOD;
if ( b % 2 == 1)
aux = (a * aux) % MOD;
return aux;
}
int main()
{
fin >> a >> b;
fout << Ridicare(a, b);
}