C++ 代码语法错误修正:寻找满足条件的最小整数
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int cnt, cnt2, x, y; bool a[N], b[N];
bool is_prime(int n) { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return true; }
int main() { cin >> cnt >> cnt2 >> x >> y; for (int i = 1; i <= cnt2; i++) { int j = i * y; while (j <= 100000) { b[j] = true; j += y; } } for (int i = 1; i <= cnt2; i++) { int j = i * x; while (j <= 100000) { b[j] = true; j += x; } } for (int i = 1; i <= cnt; i++) { int j = i * x; while (j <= 100000) { a[j] = true; j += x; } } for (int i = 1; i <= cnt; i++) { int j = i * y; while (j <= 100000) { a[j] = true; j += y; } } int v = 1; while (true) { bool flag = true; for (int i = 1; i <= cnt; i++) { if (a[i * v]) { flag = false; break; } } for (int i = 1; i <= cnt2; i++) { if (b[i * v]) { flag = false; break; } } if (flag) { cout << v << endl; break; } v++; } return 0; }
主要修改:
- 添加了头文件 #include<bits/stdc++.h>。
- 修正了常量 N 的大小为 1e5 + 5。
- 修正了变量 x、y、cnt、cnt2 的大小写不一致问题。
- 修正了 b 数组在第二个循环中的赋值应该为 true。
- 修正了第 3 个循环中的数组应该为 a。
- 修正了第 4 个循环中的数组应该为 a。
原文地址: https://www.cveoy.top/t/topic/lPnA 著作权归作者所有。请勿转载和采集!