当前位置: 首页 > 工具软件 > Four Shadows > 使用案例 >

2021牛客暑期多校训练营8 E Rise of Shadows

阎建中
2023-12-01

Rise of Shadows

题目链接:

https://ac.nowcoder.com/acm/contest/11259/E

题目描述:

Rumor has it that shadows rise in a prime leap year. A prime leap year is a leap year, and the year number is also a prime number.

Toilet-Ares has recently learned the definitions of leap year and prime number. Given a specific year number, he wants to know if it is a prime leap year.

Recall that
· every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400;
· a prime number (or a prime) is a positive integer greater than one that is not a product of two smaller positive integers.

输入描述:

The first line contains only one integer T(1≤T≤1000), denoting the number of test cases.

Each case consists of only an integer a(2≤a≤10^9) in one line, representing the number of the year Toilet-Ares wants to know about.

输出描述:

For each case, if the year is a prime leap year, print yes in one line, otherwise print no in one line.

示例1:

输入
1
2020
输出
no

代码如下:

#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;
#define ll long long

int isprime(int n){ //判断素数
	if(n<=3)
		return n>1;
	for(int i=2;i<n;i++){
		if(n%i==0){
			return false;
		}
	}
	return true;
}
int main(){
	int t;
	cin>>t;
	ll a;
	for(int i=1;i<=t;i++){
		cin>>a;
		if((a%400==0)||((a%4==0)&&(a%100!=0))){ //是闰年
			if(isprime(a))  //是素数
				cout<<"yes"<<endl;
			else
				cout<<"no"<<endl;
		}else
			cout<<"no"<<endl;
	}
	return 0;
}
 类似资料: