Cod sursa(job #2816863)
Utilizator | Data | 12 decembrie 2021 12:53:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.58 kb |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1999999973;
int mult(int a, int b) {
long long ras = a;
ras = ras * b;
while (ras >= MOD)
ras -= MOD;
return ras;
}
long long put(int base, int exp) {
long long ans = 1;
while (exp) {
if ((exp & 1))
ans = mult(ans, base);
base = mult(base, base);
exp >>= 1;
}
return ans;
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n,p;
fin >> n >> p;
fout << put(n, p);
return 0;
}