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
xmody=0
Is there any way to satisfy everyone's requirement?
Every test case contains one line with two integers n , s .
Limits
1≤T≤100 .
1≤n≤109 .
0≤s≤109
If there is any way to satisfy everyone's requirement, y equals 'Yes', otherwise y equals 'No'.
2 5 14 4 11
Case #1: No Case #2: Yes
/*
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5943
题目大意:
给定S,N,把S+1,S+2,...S+N这N个数填到1,2,...,N里,要求X只能填到X的因子的位置。
(即X%Y=0,那么X才能放在Y位置)
问是否能够放满。
题目思路: 【二分图匹配 匈牙利算法】
首先,如果S<N,那么S+1,S+2...N这些数直接放在S+1,S+2...N的位置上
(如果其他数x放在这些位置上面,这些数不放在对应位置,那么x一定能放在这些数放的位置,所以直接交换即可)
所以可以直接将S和N调换,缩小N。
接着看N个连续的数,如果出现2个素数。那么必然无解(都只能放1)
所以可以估算一下素数的最大间隔(我取504),N超过必然无解。
N小于504的情况下,直接暴力建边(能整除就连边),然后跑二分图匹配即可。
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int MAXN=1000;
ll L1,L2,R1,R2; //u,v数目
int g[MAXN][MAXN];//编号是0~n-1的
int linker[MAXN];
bool used[MAXN];
bool dfs(int u)
{
ll v;
for(v=1;v<=R1-L1+1;v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
}
int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=1;u<=R2;u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
}
bool is_prime(ll num)
{
ll i,j,n=sqrt(num);
if(num==2) return true;
for(i=2;i<=n;i++) {
if(num%i==0) return false;
}
return true;
}
int main()
{
ll i,j,n,s;
int T,cnt;
cin>>T;
for(int _=1;_<=T;_++) {
cin>>n>>s;
L1=max(s+1,n+1),R1=s+n;
R2=min(n,s),L2=1;
if(s==0) {
cout<<"Case #"<<_<<": Yes"<<endl;
continue;
}
for(i=L1,cnt=0;i<=R1;i++) {
if(is_prime(i)) cnt++;
if(cnt==2) break;
}
if(i<=R1) {
cout<<"Case #"<<_<<": No"<<endl;
continue;
}
memset(g,0,sizeof(g));
for(i=L2;i<=R2;i++) {
for(j=L1;j<=R1;j++) {
if(j%i==0) g[i][j-L1+1]=1;
}
}
if(hungary()==R2) {
cout<<"Case #"<<_<<": Yes"<<endl;
continue;
}
else {
cout<<"Case #"<<_<<": No"<<endl;
continue;
}
}
return 0;
}