Pagini recente » Cod sursa (job #2772784) | Cod sursa (job #517050) | Cod sursa (job #1071178) | Cod sursa (job #3005516) | Cod sursa (job #2415479)
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
ifstream fin("ecuatie.in");
ofstream fout("ecuatie.out");
long long A,B,C,a,b,c,k,d,p1,p2,q1,q2,u1,u2,i,j,cnt;
long long v[100000],w[100000];
void af(int a, int b, int c, int d){
fout<<"(";
if(a<0)
fout<<"-";
if(abs(a)!=1)
fout<<abs(a);
fout<<"x";
if(b<0)
fout<<"-";
else
fout<<"+";
fout<<abs(b);
fout<<")(";
if(c<0)
fout<<"-";
if(abs(c)!=1)
fout<<abs(c);
fout<<"x";
if(d<0)
fout<<"-";
else
fout<<"+";
fout<<abs(d);
fout<<")";
}
int main(){
fin>>A>>B>>C>>k;
a=max(A,-A);
c=max(C,-C);
for(d=1;d*d<=c;d++)
if(c%d==0){
w[++u2]=d;
w[++u2]=-d;
if(d!=c/d)
w[++u2]=c/d,w[++u2]=-c/d;
}
sort(w+1,w+u2+1);
for(d=1;d*d<=a;d++)
if(a%d==0){
v[++u1]=d;
v[++u1]=-d;
if(d!=a/d)
v[++u1]=a/d,v[++u1]=-a/d;
}
sort(v+1,v+u1+1);
for(i=1;i<=u1;i++){
for(j=1;j<=u2;j++){
p1=v[i]; p2=A/v[i];
q1=w[j]; q2=C/w[j];
if(p1*q2+p2*q1==B)
cnt++;
if(cnt==k){
af(p1,q1,p2,q2);
return 0;
}
}
}
fout<<-1;
return 0;
}