Cod sursa(job #1904913)
Utilizator | Data | 5 martie 2017 20:43:46 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int lg_pow(int base, int exp)
{
int answ = 1;
while (exp != 0) {
if (exp & 1)
answ = (1LL * answ * base) % MOD;
base = (1LL * base * base) % MOD;
exp >>= 1;
}
return answ;
}
int main()
{
int b, p;
f >> b >> p;
g << lg_pow(b, p);
}