Kingdom of Obsession
分类:
版权声明:本文为棒(xian)棒(yu)博主原创文章,转载请注明出处哦~
Kingdom of Obsession
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Problem Description
There is a kindom of obsession, so people in this kingdom do things very strictly.
They name themselves in integer, and there are n people with their id continuous (s+1,s+2,⋯,s+n) standing in a line in arbitrary order, be more obsessively, people with id x wants to stand at yth position which satisfy
Is there any way to satisfy everyone's requirement?
They name themselves in integer, and there are n people with their id continuous (s+1,s+2,⋯,s+n) standing in a line in arbitrary order, be more obsessively, people with id x wants to stand at yth position which satisfy
xmody=0
Is there any way to satisfy everyone's requirement?
Input
First line contains an integer T, which indicates the number of test cases.
Every test case contains one line with two integers n, s.
Limits
1≤T≤100.
1≤n≤109.
0≤s≤109.
Every test case contains one line with two integers n, s.
Limits
1≤T≤100.
1≤n≤109.
0≤s≤109.
Output
For every test case, you should output 'Case #x: y', where x indicates the case number and counts from 1 and y is the result string.
If there is any way to satisfy everyone's requirement, y equals 'Yes', otherwise y equals 'No'.
If there is any way to satisfy everyone's requirement, y equals 'Yes', otherwise y equals 'No'.
Sample Input
2 5 14 4 11
Sample Output
Case #1: No Case #2: Yes
题意:我想来到这的都不用讲什么题意的吧。
思路:估计也都能想到利用二分图最大匹配来确定是不是能够全匹配,重点是n很大啊。
不过我们知道素数有个特性就是因数只有1和它本身。所以素数只能待在位置1或者标号为本身的位置上
1.如果m>n
如果n大于等于两个素数之间的距离,那么肯定是不可能匹配的。
如果小于直接二分图匹配一下。
2.如果m<=n
黄色部分长度为m如果m的长度大于等于两个素数的间隔那肯定是不符合题意。
如果小于那么就把m部分二分图匹配,匹配的话肯定符合题意,不匹配的话不符合题意,至于为什么不和重合部分匹配,看评论。
这两个一综合就会发现第二种如果mn互换和第一种是一样的。
至于二分图匹配:
就是n个点之间的匹配,如果两个点之间满足等式就连一条边,最后看看能不能全匹配上就可以了。