Pagini recente » Cod sursa (job #2739424) | Cod sursa (job #1981486) | Cod sursa (job #2535542) | Cod sursa (job #421218) | Cod sursa (job #2522592)
#include <bits/stdc++.h>
using namespace std;
const int DIM = 1e5 + 5;
pair<int, int> divA[DIM], divC[DIM];
int main(void) {
freopen("ecuatie.in", "r", stdin);
freopen("ecuatie.out", "w", stdout);
int a, b, c, k;
cin >> a >> b >> c >> k;
int aa = abs(a), cc = abs(c);
int n = 0;
for (int i = 1; i * i <= aa; ++i) {
if (aa % i == 0) {
divA[++n] = make_pair(i, a / i);
divA[++n] = make_pair(-i, -a / i);
if (i != aa / i) {
divA[++n] = make_pair(a / i, i);
divA[++n] = make_pair(-a / i, -i);
}
}
}
sort(divA + 1, divA + n + 1);
int m = 0;
for (int i = 1; i * i <= cc; ++i) {
if (cc % i == 0) {
divC[++m] = make_pair(i, c / i);
divC[++m] = make_pair(-i, -c / i);
if (i != cc / i) {
divC[++m] = make_pair(c / i, i);
divC[++m] = make_pair(-c / i, -i);
}
}
}
sort(divC + 1, divC + m + 1);
int nr = 0;
for (int i = 1; i <= n; ++i) {
int x, xx, y, yy;
tie(x, xx) = divA[i];
for (int j = 1; j <= m; ++j) {
tie(y, yy) = divC[j];
if (xx * y + yy * x == b)
++nr;
if (nr == k) {
cout << "(";
if (x == -1) cout << "-";
else if (x != 1) cout << x;
cout << "x";
if (y > 0) cout << "+";
cout << y;
cout << ")";
cout << "(";
if (xx == -1) cout << "-";
else if (xx != 1) cout << xx;
cout << "x";
if (yy > 0) cout << "+";
cout << yy;
cout << ")";
return 0;
}
} }
cout << -1;
return 0;
}