Alice has a lovely piece of cloth. It has the shape of a square with a side of length a centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length b centimeters (where b<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 t (1≤t≤5) — the number of test cases.
Each of the next t lines describes the i-th test case. It contains two integers a and b (1≤b<a≤1011) — the side length of Alice’s square and the side length of the square that Bob wants.
Output
Print t lines, where the i-th line is the answer to the i-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
4
6 5
16 13
61690850361 24777622630
34 33
Output
YES
NO
NO
YES
判断a2-b2是不是素数,看到数大先想的是欧拉筛。。。总是想暴力思维题。。。
思路:a2-b2=(a+b)(a-b),然后,素数的定义是是除了数字一和本身之外不能被其他任何的数字除尽,所以如果我们让a-b=1,a+b是素数,那么所求的a2-b2就可以输出YES。数大,记得用long long。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
bool isPrime(long long n) {
long long i;
if(n<2)
return false;
for(i = 2; i <= sqrt(n); i++)
{
if((n % i) == 0)
return false;
}
return true;
}
int main()
{
int k;
scanf("%d",&k);
while(k--)
{
int flag=0;
long long a,b;
scanf("%lld %lld",&a,&b);
if((a-b)==1)
{
if(isPrime(a+b))
flag=1;
}
if(flag)
printf("YES\n");
else
{
printf("NO\n");
}
}
return 0;
}