Cod sursa(job #2760638)
| Utilizator | Data | 28 iunie 2021 13:56:47 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.35 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n, p;
fin >> n >> p;
int
rez = 1;
while (p) {
if (p%2 == 1) {
rez = rez * n;
}
n = n*n;
p = p/2;
}
fout << rez;
fin.close();
fout.close();
return 0;
}