关于这次SCP-J完善程序第二题
  • 板块灌水区
  • 楼主huangboning
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/8/20 15:20
  • 上次更新2024/8/20 17:04:14
查看原帖
关于这次SCP-J完善程序第二题
478234
huangboning楼主2024/8/20 15:20

(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)xy(w-z+1)为什么会是质数

2024/8/20 15:20
加载中...