#include #include #include using namespace std; // f = a/b double checkv(const vector& x){ double c = 0.0; for(auto q : x){ c += 1.0 / q; } return c; //return fabs(c - r) < 1e-9; // 浮点数近似比较 } //以step作为迭代标志 bool dfs(vector& path, int step, int max_depth, int a, int b, int max_val){ double r = static_cast(a) / b; if(fabs(checkv(path) - r) < (1e-9)){ for(int x : path) cout << x << " "; cout << endl; return true; } if(checkv(path) > r + (1e-9)) return false; if(step == max_depth) return false; int start = path.empty() ? 1 : path.back(); for(int i = start; i <= max_val; i++){ path.push_back(i); if(dfs(path, step + 1, max_depth, a, b, max_val)) return true; path.pop_back(); } return false; } bool ids(int limit, int a, int b, int max_val){ for(int depth = 1; depth <= limit; depth++){ vector path; if(dfs(path, 0, depth, a, b, max_val)) return true; } return false; } int main(){ int aa, bb, max; cin >> aa >> bb; max = 200; ids(10, aa, bb, max); return 0; }