Today is the 822th day of learning programming with a slightly cold rain!
Hello, everyone! This is the CSP 2024 Group J Preliminary Exam Questions.
Day 822


CSP 2024 Group J Preliminary Exam Questions
Read the Program
2. Read the Program (The program input does not exceed the defined range of arrays or strings; for true/false questions, fill in √ for correct and ⨉ for incorrect; unless otherwise specified, true/false questions are worth 1.5 points, multiple-choice questions are worth 3 points, totaling 40 points)
Question 1

True/False Questions
1. When the input is 10, the first output of the program is 44, and the second output is 17. ( )
2. If the condition in the isPrime(i) function is changed to i<=n/2, when inputting 20, the output of countPrimes(20) will change to 6. ( )
3. The sumPrimes function calculates the sum of all prime numbers between 2 and n.
Multiple Choice Questions
1. When the input is 50, the output of sumPrimes(50) is ( ).
A. 1060
B. 328
C. 381
D. 275
2. If the for (int i = 2; i * i <= n; i++) is changed to for (int i = 2; i <= n; i++), when inputting 10, the program’s output is ( ).
A. It will not correctly calculate the number of primes and their sum below 10
B. Still outputs 4 and 17
C. Outputs 3 and 10
D. The output remains unchanged, but the runtime is shorter
Answer: B
START OF SPRING
Solution: This question tests the logic of prime number determination in C++.
True/False Questions
1. True
Explanation: The prime numbers between 2 and 10 are 4 in total: 2, 3, 5, 7. Their sum is 17. Therefore, the first question is correct.
2. False
There are 8 prime numbers between 2 and 10: 2, 3, 5, 7, 11, 13, 17, 19. So the judgment is incorrect.
3. True
The function of sumPrimes is indeed to calculate the sum of all prime numbers between 2 and n.
Multiple Choice Questions
1. B
The prime numbers between 2 and 50 are:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47.
The total sum is 328. So the answer is B.
2. A
Explanation: Because changing to <=n means that every judgment will return false, every number will be determined as non-prime. So the answer is A.

20
25
8

AUGUST
Day
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
1
Army Day
2
9th Day
3
10th Day
4
11th Day
5
12th Day
6
13th Day
7
Beginning of Autumn
8
National Fitness Day
9
End of the Last Heat
10
17th Day
11
18th Day
12
19th Day
13
20th Day
14
21st Day
15
22nd Day
16
23rd Day
17
24th Day
18
25th Day
19
Doctor’s Day
20
27th Day
21
28th Day
22
29th Day
23
End of Heat
24
2nd Day
25
3rd Day
26
4th Day
27
5th Day
28
6th Day
29
Qixi Festival
30
8th Day
31
9th Day
@秀米XIUMI
With a slightly cold rain
Open Wisdom Station
