fork download
  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<iostream>
  6. #include<fstream>
  7. #include<map>
  8. #include<ctime>
  9. #include<set>
  10. #include<queue>
  11. #include<cmath>
  12. #include<vector>
  13. #include<bitset>
  14. #include<functional>
  15. #define x first
  16. #define y second
  17. #define mp make_pair
  18. #define pb push_back
  19. #define REP(i,l,r) for((i)=(l);(i)<=(r);++(i))
  20. #define REP2(i,l,r) for((i)=(l);(i)!=(r);++(i))
  21. using namespace std;
  22.  
  23. typedef long long LL;
  24. typedef double ld;
  25.  
  26. const int MAX=1000+10;
  27.  
  28. int ord[MAX];
  29. int x,y,z;
  30. int ax,ay,az;
  31. int end;
  32.  
  33. int ansx,ansy,ansz;
  34. LL ans,up;
  35.  
  36. int is(int a,int b,int c,int d)
  37. {
  38. return a && b && ord[c]-ord[a]==ord[d]-ord[b];
  39. }
  40.  
  41. int gcd(int a,int b)
  42. {
  43. for(;b;)
  44. {
  45. int t=a;
  46. a=b;
  47. b=t%a;
  48. }
  49. return a;
  50. }
  51.  
  52. int LCM(int a,int b)
  53. {
  54. return a/gcd(a,b)*b;
  55. }
  56.  
  57. LL check()
  58. {
  59. if(is(ax,ay,x,y))
  60. return 0;
  61. if(is(ax,az,x,z))
  62. return 0;
  63. if(is(ay,az,y,z))
  64. return 0;
  65. int ta=2*x/gcd(2*x,ax);
  66. int tb=2*y/gcd(2*y,ay);
  67. int tc=2*z/gcd(2*z,az);
  68. int T=LCM( LCM(ta,tb) , tc );
  69. if(T>=up)
  70. end=1;
  71. return (LL)T*(ax+ay+az);
  72. }
  73.  
  74. void Main()
  75. {
  76. scanf("%d%d%d",&x,&y,&z);
  77. int sum=x+y+z;
  78. end=0;
  79. ans=0;
  80. up=2* LCM ( LCM(x,y) , z );
  81. for(sum--;sum;sum--)
  82. for(ax=min(sum,x);ax>=x-47;--ax)
  83. for(ay=min(sum-ax,y);ay>=y-47;--ay)
  84. {
  85. az=sum-ax-ay;
  86. if(az<0 || az>z)
  87. continue;
  88. if(gcd( gcd(ax,ay) , az ) != 1)
  89. continue;
  90. LL tmp=check();
  91. if(tmp>ans)
  92. {
  93. ans=tmp;
  94. ansx=ax;
  95. ansy=ay;
  96. ansz=az;
  97. }
  98. if(end)
  99. return;
  100. }
  101. return;
  102. }
  103.  
  104. int main()
  105. {
  106. // freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  107. int i;
  108. REP2(i,1,MAX)
  109. {
  110. int u=i;
  111. for(;u%2==0;u/=2)
  112. ord[i]++;
  113. }
  114. int T;
  115. scanf("%d",&T);
  116. while(T--)
  117. {
  118. Main();
  119. printf("%d %d %d\n",ansx,ansy,ansz);
  120. }
  121. return 0;
  122. }
Runtime error #stdin #stdout 0s 3300KB
stdin
Standard input is empty
stdout
Standard output is empty