Cod sursa(job #2982172)
Utilizator | Data | 19 februarie 2023 17:35:25 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
long long int n, p, rezultat = 1;
fin >> n >> p;
if(n == 1 || n == 0)
{
fout << 1;
return 0;
}
while(p > 1)
{
if(p % 2 == 0)
{
n = n * n;
p = p / 2;
}
if(p % 2 == 1 && p != 1)
{
rezultat = n * rezultat;
p--;
}
}
fout << n * rezultat;
}