Cod sursa(job #3288539)
| Utilizator | Data | 22 martie 2025 16:48:48 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1999999973;
long long pow(int n, int p)
{
if(p == 0)
{
return 1;
}
if((p & 1))
{
return (n * pow(n, p - 1)) % MOD;
}
else
{
return pow(n * n, (p >> 1));
}
}
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
cin.tie(nullptr)->sync_with_stdio(false);
int n, p;
cin >> n >> p;
cout << pow(n, p);
}