Cod sursa(job #1188253)
| Utilizator | Data | 19 mai 2014 10:25:05 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
using namespace std;
const long long MOD = 1999999973LL;
long long N, P;
inline long long PutLog(long long baza, long long exp)
{
if (exp == 0)
return 1LL;
if (exp & 1)
return 1LL * baza * PutLog(baza, exp - 1) % MOD;
long long aux = PutLog(baza, exp/2);
return 1LL * aux * aux % MOD;
}
int main()
{
ifstream f("lgput.in");
f >> N >> P;
f.close();
ofstream g("lgput.out");
g << PutLog(N, P) << "\n";
g.close();
return 0;
}
