Cod sursa(job #1414281)
| Utilizator | Data | 2 aprilie 2015 14:50:29 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
using namespace std;
#define MOD 1999999973
ifstream f("lgput.in");
ofstream g("lgput.out");
int n, p;
int lgput(int base, int exp)
{
int res = 1;
while (exp != 0) {
if (exp % 2 == 1)
res = (1LL * res * base) % MOD;
base = (1LL * base * base) % MOD;
exp >>= 1;
}
return res;
}
int main()
{
f >> n >> p;
int sol = lgput(n, p);
g << sol;
}