Cod sursa(job #2531463)
| Utilizator | Data | 26 ianuarie 2020 12:22:54 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const int MOD = 1999999973;
int N, P;
static inline int lgput (int n, int p, int Mod)
{
long long ans = 1, aux = n;
for(int i = 0; (1 << i) <= p; ++i)
{
if(p & (1 << i))
ans = (ans * aux) % Mod;
aux = (aux * aux) % Mod;
}
return ans;
}
int main ()
{
f.tie(NULL);
f >> N >> P;
g << lgput(N, P, MOD) << '\n';
return 0;
}
