Cod sursa(job #3289070)
| Utilizator | Data | 25 martie 2025 14:46:24 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int MOD = 1999999973;
int lgput(int n, int a)
{
if(a==0)
{
return 1;
}
else if(a%2 == 0)
{
int val = lgput(n, a/2);
return (val*val) % MOD;
}
else
{
return (n * lgput(n, a - 1)) % MOD;
}
}
int main()
{
int n, p;
fin >> n >> p;
fout << lgput(n, p);
return 0;
}
