Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- int a,b,c,end=0,ans[3];
- scanf("%d%d%d",&a,&b,&c);
- if(c!=0)
- {
- for(int i=1;i<=sqrt(abs(c));i++)
- {
- if(c%i==0)
- {
- for(int j=i;j<=sqrt(abs(c/i));j++)
- {
- if((c/i)%j==0)
- {
- int f1[2],f2[2],f3[2];
- f1[0]=i;f1[1]=-i;f2[0]=j;f2[1]=-j;f3[0]=c/(i*j);f3[1]=-c/(i*j);
- for(int d1=0;d1<2;d1++)
- {
- for(int d2=0;d2<2;d2++)
- {
- for(int d3=0;d3<2;d3++)
- {
- if(f1[d1]+f2[d2]+f3[d3]==a&&f1[d1]*f2[d2]+f1[d1]*f3[d3]+f2[d2]*f3[d3]==b&&f1[d1]*f2[d2]*f3[d3]==c)
- {
- ans[0]=f1[d1];ans[1]=f2[d2];ans[2]=f3[d3];
- end=1;
- }
- }
- }
- }
- }
- }
- }
- if(end) break;
- }
- }
- else if(c==0&&b!=0)
- {
- for(int i=1;i<=sqrt(abs(b));i++)
- {
- if(b%i==0)
- {
- int f1[2],f2[2];
- f1[0]=i;f1[1]=-i;f2[0]=b/i;f2[1]=-b/i;
- for(int d1=0;d1<2;d1++)
- {
- for(int d2=0;d2<2;d2++)
- {
- if((f1[d1]+f2[d2])==a&&f1[d1]*f2[d2]==b)
- {
- ans[0]=0;ans[1]=f1[d1];ans[2]=f2[d2];
- end=1;
- }
- }
- }
- }
- if(end) break;
- }
- }
- else {
- ans[0]=0;ans[1]=0;ans[2]=a;
- }
- for(int i=0;i<3;i++)
- {
- for(int j=i;j<3;j++)
- {
- if(ans[j]<ans[i])
- {
- int t=ans[i];
- ans[i]=ans[j];
- ans[j]=t;
- }
- }
- }
- for(int i=0;i<3;i++)
- printf("%d ",ans[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement