Cod sursa(job #3166990)
Utilizator | Data | 9 noiembrie 2023 21:18:36 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
int main()
{
int n,p;
fin >> n >> p;
while (p>0){
if (p%2==0){
n *= n;
p /= 2;
}else{
p -= 1;
p /= 2;
n *= n;
}
}
fout << n;
return 0;
}