📝 ### 第21题 **阅读程序(二)**(下列程序供第 21~24 题使用;判断题正确填 √,错误填 ×) ```cpp 01 #include <iostream> 02 using namespace std; 03 04 int gcd(int a, …
📂 C++
· ⚡ 难度 5
· ❓ 判断题
· 📖 CSP-J 第一轮考前模拟题(2026 年版)
### 第21题
**阅读程序(二)**(下列程序供第 21~24 题使用;判断题正确填 √,错误填 ×)
```cpp
01 #include <iostream>
02 using namespace std;
03
04 int gcd(int a, int b) {
05 if (b == 0) return a;
06 return gcd(b, a % b);
07 }
08
09 int main() {
10 int n, ans = 0;
11 cin >> n;
12 for (int i = 1; i <= n; i++) {
13 for (int j = i + 1; j <= n; j++) {
14 if (gcd(i, j) == 1) ans++;
15 }
16 }
17 cout << ans << endl;
18 return 0;
19 }
```
**判断题**:当输入为 2 时,程序输出为 1。( )