Pagini recente » Cod sursa (job #2438621) | Cod sursa (job #2645013) | Cod sursa (job #1525395) | Cod sursa (job #1816515) | Cod sursa (job #2217300)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int X, P;
void read(void)
{
fin >> X >> P;
}
long long int exp_by_squaring(long long int x, long long int n)
{
if (n < 0)
{
exp_by_squaring(1 / x, -n);
}
else if (n == 0)
{
return 1;
}
else if (n == 1)
{
return x;
}
else if (n % 2 == 0)
{
return exp_by_squaring(x * x, n / 2);
}
else if (n % 2 != 0)
{
return x * exp_by_squaring(x * x, (n - 1) / 2);
}
}
void print(void)
{
fout << exp_by_squaring(X, P);
}
int main(void)
{
read();
print();
return 0;
}