A12014 | Square Difference
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.](https://en.wikipedia.org/wiki/Prime_number) Could you help her to determine it?
Alice would like to know whether the area of her cloth expressed in square centimeters is [prime.](https://en.wikipedia.org/wiki/Prime_number) Could you help her to determine it?
输入格式
The first line contains a number $t$ ( $1 \leq t \leq 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 \leq b < a \leq 10^{11})$ — the side length of Alice's square and the side length of the square that Bob wants.
Each of the next $t$ lines describes the $i$ -th test case. It contains two integers $a$ and $b~(1 \leq b < a \leq 10^{11})$ — the side length of Alice's square and the side length of the square that Bob wants.
输出格式
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).
You can print each letter in an arbitrary case (upper or lower).
输入输出样例
输入 #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 $6^2 - 5^2 = 36 - 25 = 11$ , which is prime, so the answer is "YES".
In the second case, the area is $16^2 - 13^2 = 87$ , which is divisible by $3$ .
In the third case, the area of the remaining piece is $61690850361^2 - 24777622630^2 = 3191830435068605713421$ . This number is not prime because $3191830435068605713421 = 36913227731 \cdot 86468472991 $ .
In the last case, the area is $34^2 - 33^2 = 67$ .
In the second case, the area is $16^2 - 13^2 = 87$ , which is divisible by $3$ .
In the third case, the area of the remaining piece is $61690850361^2 - 24777622630^2 = 3191830435068605713421$ . This number is not prime because $3191830435068605713421 = 36913227731 \cdot 86468472991 $ .
In the last case, the area is $34^2 - 33^2 = 67$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted