Educational Codeforces Round 52 (Rated for Div. 2) A B题解

传送门

A. King Escape

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Alice and Bob are playing chess on a huge chessboard with dimensions n×nn×n. Alice has a single piece left — a queen, located at (ax,ay)(ax,ay), while Bob has only the king standing at (bx,by)(bx,by). Alice thinks that as her queen is dominating the chessboard, victory is hers.

But Bob has made a devious plan to seize the victory for himself — he needs to march his king to (cx,cy)(cx,cy)in order to claim the victory for himself. As Alice is distracted by her sense of superiority, she no longer moves any pieces around, and it is only Bob who makes any turns.

Bob will win if he can move his king from (bx,by)(bx,by) to (cx,cy)(cx,cy) without ever getting in check. Remember that a king can move to any of the 88 adjacent squares. A king is in check if it is on the same rank (i.e. row), file (i.e. column), or diagonal as the enemy queen.

Find whether Bob can win or not.

Input

The first line contains a single integer nn (3≤n≤10003≤n≤1000) — the dimensions of the chessboard.

The second line contains two integers axax and ayay (1≤ax,ay≤n1≤ax,ay≤n) — the coordinates of Alice's queen.

The third line contains two integers bxbx and byby (1≤bx,by≤n1≤bx,by≤n) — the coordinates of Bob's king.

The fourth line contains two integers cxcx and cycy (1≤cx,cy≤n1≤cx,cy≤n) — the coordinates of the location that Bob wants to get to.

It is guaranteed that Bob's king is currently not in check and the target location is not in check either.

Furthermore, the king is not located on the same square as the queen (i.e. ax≠bxax≠bx or ay≠byay≠by), and the target does coincide neither with the queen's position (i.e. cx≠axcx≠ax or cy≠aycy≠ay) nor with the king's position (i.e. cx≠bxcx≠bx or cy≠bycy≠by).

Output

Print "YES" (without quotes) if Bob can get from (bx,by)(bx,by) to (cx,cy)(cx,cy) without ever getting in check, otherwise print "NO".

You can print each letter in any case (upper or lower).

Examples

input

Copy

8
4 4
1 3
3 1

output

Copy

YES

input

Copy

8
4 4
2 3
1 6

output

Copy

NO

input

Copy

8
3 5
1 2
6 1

output

Copy

NO

Note

In the diagrams below, the squares controlled by the black queen are marked red, and the target square is marked blue.

In the first case, the king can move, for instance, via the squares (2,3)(2,3) and (3,2)(3,2). Note that the direct route through (2,2)(2,2) goes through check.

In the second case, the queen watches the fourth rank, and the king has no means of crossing it.

In the third case, the queen watches the third file.

题意:题意就是在国王移动的时候,x轴和y轴不能与女王的x轴和y轴相等

#include<iostream>
#include<algorithm>
#include<cstring>
#define N 0x3f3f3f3f
#define ll long long
using namespace std;

int main()
{
	int n;
	//memset(map,0,sizeof(map));
	cin>>n;
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	if(c<a&&e<a&&d<b&&f<b)
	{
		if(e-a!=f-b)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	else if(c<a&&e<a&&d>b&&f>b)
	{
		if(e-a!=f-b)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	else if(c>a&&e>a&&d<b&&f<b)
	{
		if(e-a!=f-b)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	else if(c>a&&e>a&&d>b&&f>b)
	{
		if(e-a!=f-b)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	else
	cout<<"NO"<<endl;
	return 0;
}

      B. Square Difference

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Alice has a lovely piece of cloth. It has the shape of a square with a side of length aa centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length bb centimeters (where b<ab<a). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).

Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?

Input

The first line contains a number tt (1≤t≤51≤t≤5) — the number of test cases.

Each of the next tt lines describes the ii-th test case. It contains two integers aa and b (1≤b<a≤1011)b (1≤b<a≤1011) — the side length of Alice's square and the side length of the square that Bob wants.

Output

Print tt lines, where the ii-th line is the answer to the ii-th test case. Print "YES" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print "NO".

You can print each letter in an arbitrary case (upper or lower).

Example

input

Copy

4
6 5
16 13
61690850361 24777622630
34 33
output

Copy

YES
NO
NO
YES
Note

The figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is 62−52=36−25=1162−52=36−25=11, which is prime, so the answer is "YES".

In the second case, the area is 162−132=87162−132=87, which is divisible by 33.

In the third case, the area of the remaining piece is 616908503612−247776226302=3191830435068605713421616908503612−247776226302=3191830435068605713421. This number is not prime because 3191830435068605713421=36913227731⋅864684729913191830435068605713421=36913227731⋅86468472991.

In the last case, the area is 342−332=67342−332=67.

 

题意:

就是从一个大的正方形取一个小的正方形,剩下的面积是一个质数

 

理解:考察质数的应用 

定理:

质数乘质数等于合数
合数:
合数,指自然数中除了能被1和本身整除外,还能被其他数(0除外)整除的数。与之相对的是质数(因数只有1和它本身,如2,3,5,7,11,13等等,也称素数),而1既不属于质数也不属于合数。

任何一个合数,都可以写成两个或者两个以上的质数相乘的形式

 

对于 a^2-b^2=(a+b)(a-b),  那么就可以知道如果这个是一个质数那么只能其一个是质数  所以 a-b  为1
 

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define N 0x3f3f3f3f
#define ll long long
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
	ll a,b;
	cin>>a>>b;
	ll c=a+b;
	int flag=0;
	for(int i=2;i<=sqrt(a+b);i++)
	{
		if(c%i==0)
		flag=1;
	}
	if(flag==0&&a-b==1)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	}
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值