Cod sursa(job #3331464)
| Utilizator | Data | 28 decembrie 2025 14:17:21 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
int main()
{
long long n , p , e , r=1;
fin >> n >> p;
while(p>1)
{
if(p%2==0)
{
n=pow(n, 2);
p=p/2;
}
else
{
r=r*n;
n = pow (n, 2);
p=p/2;
}
}
fout << r*n;
return 0;
}