【水打表】#69 A. Panoramix's Prediction

在古罗马背景下,通过判断连续两天击败的士兵数量是否构成素数及其紧随的素数,来预测末日是否来临。此问题需遍历50以内的素数列表进行比对。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Panoramix's Prediction
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 273 are prime, and 16,4 are not.

The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.

One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.

Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly x Roman soldiers, where x is a prime number, and next day they beat exactly y Roman soldiers, where y is the next prime number after x, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.

Yesterday the Gauls beat n Roman soldiers and it turned out that the number n was prime! Today their victims were a troop of mRomans (m > n). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?

Input

The first and only input line contains two positive integers — n and m (2 ≤ n < m ≤ 50). It is guaranteed that n is prime.

Pretests contain all the cases with restrictions 2 ≤ n < m ≤ 4.

Output

Print YES, if m is the next prime number after n, or NO otherwise.

Sample test(s)
input
3 5
output
YES
input
7 11
output
YES
input
7 9
output
NO





问m是不是n的下一个整数,那就先把50以内的素数背出来呗~

然后从第一个开始一个一个往下看~ 啊当然如果m不在这个素数表里那肯定就是NO啦,然后看n是否在m和m前的素数间啦,要注意的是区间范围是左闭右开哦

#include <cstdio>
#include <string>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
// http://codeforces.com/contest/80  
// Panoramix's Prediction1 

int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};

int main()
{
	int n,m;	cin>>n>>m;
	for(int i=0;i<=14;i++)
	{
		if(prime[i]>n)
		{
			if(prime[i]==m)
			{
				cout<<"YES";
				return 0;
			}
			cout<<"NO";
			return 0;
		}
	}
	cout<<"NO";
	return 0;
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值