(2)(好运的日期)一个日期可以用 x 年 y 月 z 日来表示。我们称一个日期是好运的,当且 仅当 xy(w-z+1)为质数,其中 w 为 x 年 y 月的总天数。输入 x,y,z,判断其对应的日期是否 好运。保证 x 是不超过 2024 的正整数,y 是不超过 12 的正整数,x,y,z 可以构成一个合法 的日期。
#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;
}
xy(w−z+1)为什么会是质数