Cod sursa(job #3182534)
Utilizator | Data | 9 decembrie 2023 09:44:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int MOD = 1999999973;
int main()
{
long long n, p, res = 1;
fin >> n >> p;
while (p)
{
if (p & 1)
res = (res * n) % MOD;
// p /= 2;
p = (p >> 1);
if (p == 0)
break;
n = (n * n) % MOD;
}
fout << res << '\n';
return 0;
}