Give a scope, ask to find out within this range to meet
n = x + y + z = x * y * z all formulas
How to solve the problem: because the decimal place here is accurate to 0.01, so first of all, X, Y, Z are 100 times times larger.
From small to large enumerations, assuming x <= y <= Z, then the range of X is in the range of (0,n ^ (1/3)],y in [X, (N-x) ^ (1/2)] so the range can be determined.
and z can be obtained by X and Y
Because x + y + z = x * y * z, and z/y are magnified 100 times times after
So (x + y + z) * 10000 = x * y * z
Distorted by formula, Z = (x + y) * 10000/(x * y-10000)
#include <cstdio>#include <algorithm>#include <cmath>#define MAXN 10010#define PO 100.0#define MIN 1e-9using namespace STD;DoubleSum1, sum2;intCntstructans{DoubleSum, A, B, C;} ANS[MAXN];BOOLCMP (ans &a, ans &b) {if(fabs(a.sum-b.sum) >= MIN)returnA.sum < B.sum;if(fabs(A.A-B.A) >= MIN)returnA.A < B.A;if(fabs(a.b-b.b) >= MIN)returnA.B < b.b;returnA.C < B.C;}voidSolve () {cnt =0;intleft = Sum1 * -, right = sum2 * -; for(inti =1; I * i * I <= right *10000; i++) for(intj = i; J * J * I <= Right *10000; J + +) {if((i * j <=10000) || ((i + j) *10000% (i * j-10000)) )Continue;intx = (i + j) *10000/(I * j-10000);if(X < I | | x < j)Continue;intsum = i + j + x;intf = i * j * x;if(f%10000)Continue;if(Sum >= left && sum <= right && (sum = f/10000) {ans[cnt].sum = Sum/po; ANS[CNT].A = I/po; ans[cnt].b = J/po; ANS[CNT].C = X/po; cnt++; }} sort (ans, ans + cnt, CMP); for(inti =0; I < CNT; i++)printf("%.2LF =%.2lf +%.2lf +%.2lf =%.2lf *%.2LF *%.2lf\n", ANS[I].SUM,ANS[I].A, ans[i].b, ans[i].c,ans[i].a,ans[i].b, ans[i].c);}intMain () { while(scanf("%LF%LF", &SUM1, &sum2) = =2) {solve (); }return 0;}
UVA-10483 the Sum Equals the Product violence