Cod sursa(job #2023220)
Utilizator | Data | 18 septembrie 2017 16:24:06 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long lgput(int x, int p)
{
long long n = 1;
while(p > 0)
{
if(p % 2 != 0)
{
n *= x;
p--;
}
x = x * x;
p /= 2;
}
return n;
}
int main()
{
int x, p;
fin >> x >> p;
fout << lgput(x, p);
return 0;
}