导航
班级管理 学习中心 题单 编程题 宠物 做题转盘 私信 我的笔记 积分管理 权限管理

📝 ### 第16题 **阅读程序(一)**(下列程序供第 16~20 题使用;判断题正确填 √,错误填 ×) ```cpp 01 #include <iostream> 02 using namespace std; 03 04 bool isPrime(int n) …

📂 C++  ·  ⚡ 难度 5  ·  ❓ 判断题  ·  📖 CSP-J 第一轮考前模拟题(2026 年版)
🏷️ CSP-J,考前模拟,阅读程序,素数,枚举
📖 CSP-J 第一轮考前模拟题(2026 年版)

### 第16题

**阅读程序(一)**(下列程序供第 16~20 题使用;判断题正确填 √,错误填 ×)

```cpp
01 #include <iostream>
02 using namespace std;
03
04 bool isPrime(int n) {
05 if (n <= 1) return false;
06 for (int i = 2; i * i <= n; i++) {
07 if (n % i == 0) return false;
08 }
09 return true;
10 }
11
12 int main() {
13 int n, cnt = 0, sum = 0;
14 cin >> n;
15 for (int i = 2; i <= n; i++) {
16 if (isPrime(i)) {
17 cnt++;
18 sum += i;
19 }
20 }
21 cout << cnt << " " << sum << endl;
22 return 0;
23 }
```

**判断题**:该程序的功能是统计 2 到 n 之间素数的个数与和。( )

🐛 反馈BUG