CF1033B.Square Difference

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 \lt 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?

爱丽丝有一块漂亮的布料,形状为边长为 aa 厘米的正方形。鲍勃也想要这样一块布料,他更希望得到一块边长为 bb 厘米的正方形(其中 b<ab \lt a)。为了使鲍勃开心,爱丽丝从自己布料的一个角上剪下所需大小的正方形送给了鲍勃。现在她只剩下一块难看的 L 形布料(见下方图片)。

爱丽丝想知道:她剩下的这块布料的面积(单位:平方厘米)是否为质数?你能帮她判断吗?

输入格式

The first line contains a number tt (1≤t≤51 \leq t \leq 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 \leq b \lt a \leq 10^{11}) — the side length of Alice's square and the side length of the square that Bob wants.

第一行包含一个数字 tt(1≤t≤51 \leq t \leq 5)——测试用例的数量。

接下来的 tt 行中,第 ii 行描述第 ii 个测试用例。该行包含两个整数 aa 和 bb(1≤b<a≤10111 \leq b \lt a \leq 10^{11})——分别为 Alice 的正方形的边长和 Bob 所需正方形的边长。

输出格式

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).

输出 tt 行,其中第 ii 行为第 ii 个测试用例的答案。如果剩余布料的面积是质数,则输出 "YES"(不带引号),否则输出 "NO"。

每个字母可以以任意大小写形式输出(大写或小写)。

输入输出样例

  • 输入#1

    4
    6 5
    16 13
    61690850361 24777622630
    34 33

    输出#1

    YES
    NO
    NO
    YES

说明/提示

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=116^2 - 5^2 = 36 - 25 = 11, which is prime, so the answer is "YES".

In the second case, the area is 162−132=8716^2 - 13^2 = 87, which is divisible by 33.

In the third case, the area of the remaining piece is 616908503612−247776226302=319183043506860571342161690850361^2 - 24777622630^2 = 3191830435068605713421. This number is not prime because $3191830435068605713421 = 36913227731 \cdot 86468472991 $.

In the last case, the area is 342−332=6734^2 - 33^2 = 67.

下图展示了第一个测试用例。蓝色部分为 Bob 所得的那块,红色部分为 Alice 留给自己的那块。红色部分的面积为 62−52=36−25=116^2 - 5^2 = 36 - 25 = 11,该数为质数,因此答案为 “YES”。

在第二个测试用例中,面积为 162−132=8716^2 - 13^2 = 87,该数可被 33 整除。

在第三个测试用例中,剩余部分的面积为 616908503612−247776226302=319183043506860571342161690850361^2 - 24777622630^2 = 3191830435068605713421。该数不是质数,因为 $3191830435068605713421 = 36913227731 \cdot 86468472991 $。

在最后一个测试用例中,面积为 342−332=6734^2 - 33^2 = 67。

输入解题思路,AI测评打分。不知道怎么写?

首页