问题描述:
一个日期可以用 x 年 y 月 z 日来表示。我们称一个日期是好运的,当且仅当 xy(w-z+1) 为质数,其中 w 为 x 年 y 月的总天数。输入 x, y, z,判断其对应的日期是否好运。
试补全线性筛法算法。
1 #include <bits/stdc++.h>
2 using namespace std; 3
4 const int MAXW = ①;
5 const int days[13] = {0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
6 int prime[MAXW], cnt;
7 bool not_prime[MAXW];
8
9 void linear_prime(int n) {
10 --n;
11 not_prime[0] = not_prime[1] = true;
12 for(int i = 2; i <= n; i++) {
13 if(not_prime[i] == false)
14 prime[++cnt]=i;
15 for(int j = 1; ②; j++) {
16 not_prime[i * prime[j]] = 1;
17 if(i % prime[j] == 0)
18 ③;
19 }
20 }
21 }
22 bool check(int n) {
23 return ④;
24 }
25
26 int main() {
27 linear_prime(MAXW);
28 int x, y, z, w;
29 cin >> x >>y >> z;
30 if(y == ⑤)
31 w = check(x) ? 29 : 28;
32 else
33 w = days[y];
34 if(not_prime[x * y * (w – z + 1)])
35 cout << "unlucky" << endl;
36 else
37 cout << "lucky" << endl;
38 return 0;
39 }
单选题:
①处可以填( )
②处应填( )
③处应填( )
④处应填( )。
⑤处应填( )。