Advertisement
Guest User

Untitled

a guest
Sep 12th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5.     int a,b,c,end=0,ans[3];
  6.     scanf("%d%d%d",&a,&b,&c);
  7.     if(c!=0)
  8.     {
  9.         for(int i=1;i<=sqrt(abs(c));i++)
  10.         {
  11.             if(c%i==0)
  12.             {
  13.                 for(int j=i;j<=sqrt(abs(c/i));j++)
  14.                 {
  15.                     if((c/i)%j==0)
  16.                     {
  17.                         int f1[2],f2[2],f3[2];
  18.                         f1[0]=i;f1[1]=-i;f2[0]=j;f2[1]=-j;f3[0]=c/(i*j);f3[1]=-c/(i*j);
  19.                         for(int d1=0;d1<2;d1++)
  20.                         {
  21.                             for(int d2=0;d2<2;d2++)
  22.                             {
  23.                                 for(int d3=0;d3<2;d3++)
  24.                                 {
  25.                                     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)
  26.                                     {
  27.                                         ans[0]=f1[d1];ans[1]=f2[d2];ans[2]=f3[d3];
  28.                                         end=1;
  29.                                     }
  30.                                 }
  31.                             }
  32.                         }
  33.                     }
  34.                 }
  35.             }
  36.             if(end) break;
  37.         }
  38.     }
  39.     else if(c==0&&b!=0)
  40.     {
  41.         for(int i=1;i<=sqrt(abs(b));i++)
  42.         {
  43.             if(b%i==0)
  44.             {
  45.                 int f1[2],f2[2];
  46.                 f1[0]=i;f1[1]=-i;f2[0]=b/i;f2[1]=-b/i;
  47.                 for(int d1=0;d1<2;d1++)
  48.                 {
  49.                     for(int d2=0;d2<2;d2++)
  50.                     {
  51.                         if((f1[d1]+f2[d2])==a&&f1[d1]*f2[d2]==b)
  52.                         {
  53.                             ans[0]=0;ans[1]=f1[d1];ans[2]=f2[d2];
  54.                             end=1;
  55.                         }
  56.                     }
  57.                 }
  58.             }
  59.             if(end) break;
  60.         }
  61.     }
  62.     else {
  63.         ans[0]=0;ans[1]=0;ans[2]=a;
  64.     }
  65.     for(int i=0;i<3;i++)
  66.     {
  67.         for(int j=i;j<3;j++)
  68.         {
  69.             if(ans[j]<ans[i])
  70.             {
  71.                 int t=ans[i];
  72.                 ans[i]=ans[j];
  73.                 ans[j]=t;
  74.             }
  75.         }
  76.     }
  77.     for(int i=0;i<3;i++)
  78.         printf("%d ",ans[i]);
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement