#12104. 珅泽教育CSP-J第一轮模拟考第二十一套 第 39 题
珅泽教育CSP-J第一轮模拟考第二十一套 第 39 题
三、完善程序(单选题,每小题 3 分,共计 30 分)
程序(2)
(好运的日期)一个日期可以用 年 月 日来表示。当且仅当 为质数时,我们称这个日期是好运的,其中 为 年 月的总天数。输入 ,判断对应日期是否好运。保证 、,且 可以构成合法日期。试补全线性筛程序,空间限制 512 MiB。
#include <bits/stdc++.h>
using namespace std;
const int MAXW = ①;
const int days[13] = {0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int prime[MAXW], cnt;
bool not_prime[MAXW];
void linear_prime(int n) {
--n;
not_prime[0] = not_prime[1] = true;
for (int i = 2; i <= n; i++) {
if (not_prime[i] == false)
prime[++cnt] = i;
for (int j = 1; ②; j++) {
not_prime[i * prime[j]] = 1;
if (i % prime[j] == 0)
③;
}
}
}
bool check(int n) {
return ④;
}
int main() {
linear_prime(MAXW);
int x, y, z, w;
cin >> x >> y >> z;
if (y == ⑤)
w = check(x) ? 29 : 28;
else
w = days[y];
if (not_prime[x * y * (w - z + 1)])
cout << "unlucky" << endl;
else
cout << "lucky" << endl;
return 0;
}
①处可以填( )。
{{ select(1) }}
753005100000000007250412024