Pagini recente » Cod sursa (job #2925296) | Cod sursa (job #3164208) | Cod sursa (job #2795483) | Cod sursa (job #2873266) | Cod sursa (job #2096484)
#include<fstream>
using namespace std;
bool binary[33];
void dtob(long a,short& i) {
if (a % 2) binary[i] = true;
if (a / 2) dtob(a / 2, ++i);
}
int main() {
int x; long P; //
ifstream in("lgput.in");
ofstream out("lgput.out");
in >> x >> P;
short n = 0;
dtob(P,n);
long long *szorzat = new long long[n];
szorzat[0] = x;
long long result = 1;
for (int i = 0;i <= n;++i) {
if (i>0) szorzat[i] = szorzat[i - 1] * szorzat[i-1];
if (binary[i]) result *= szorzat[i];
}
out << result;
}