|

楼主 |
发表于 2022-11-30 17:55:48
|
显示全部楼层
应该是,这个是错误的代码,给你看看正确的代码- #include<iostream>
- using namespace std;
- int cm(int a, int b)
- {
- int temp;
- int mul;
- mul = a * b;
- if (a % b == 0)
- return a;
- else
- {
- while (a % b != 0)
- {
- temp = a % b;
- a = b;
- b = temp;
- }
- return mul * b;
- }
- }
- int main()
- {
- int a, b, c, d;
- int temp;
- int ta, tb, tc, td;
- for (a = 20; a >= 5; a--)
- for (b = a - 1; b >= 4; b--)
- for (c = b - 1; c >= 3; c--)
- for (d = c - 1; d >= 2; d--)
- {
- temp = cm(a, b);
- temp = cm(temp, c);
- temp = cm(temp, d);
- ta = temp / a;
- tb = temp / b;
- tc = temp / c;
- td = temp / d;
- if (ta + tb + tc + td == temp)
- cout << a << "," << b << "," << c << "," << d << ","
- << "0" << endl;
- }
- return 0;
- }
复制代码- #include<iostream>
- using namespace std;
- int main(void)
- {
- float a, b, c, d;
- float x, y, z, m;
- for (x = 20; x >= 5; x--)
- {
- for (y = x - 1; y >= 4; y--)
- {
- for (z = y - 1; z >= 3; z--)
- {
- for (m = y - 1; m >= 2; m--)
- {
- if (y * z * m + x * z * m + x * y * m + x * y * z == x * y * z * m)
- {
- cout << x << "," << y << "," << z << "," << m << ","
- << "0" << endl;
- }
- }
- }
- }
- }
- }
复制代码- #include<iostream>
- using namespace std;
- int main()
- {
- float n;
- float a, b, c;
- float s1, s2, s3;
- for (n = 5; n <= 20; n++)
- {
- for (a = 1; a <= n; a++)
- for (b = 1; b <= n; b++)
- for (c = 1; c <= n; c++)
- {
- s1 = n - a;
- s2 = n - a - b;
- s3 = n - a - b - c;
- if (1 / n + 1 / s1 + 1 / s2 + 1 / s3 == 1 && s1 > 0 && s2 > 0 && s3 > 0)
- cout << n << "," << s1 << "," << s2 << "," << s3 << ","
- << "0" << endl;
- }
- }
- return 0;
- }
复制代码 |
|