A Central Meridian (ACM) Number N is a positive integer satisfies that given two positive integers A and B, and among A, B and N, we have
N | ((A^2)*B+1) Then N | (A^2+B)
Now, here is a number x, you need to tell me if it is ACM number or not.
Input
The first line there is a number T (0<T<5000), denoting the test case number.
The following T lines for each line there is a positive number N (0<N<5000) you need to judge.
Output
For each case, output “YES” if the given number is Kitty Number, “NO” if it is not.
Sample Input
2
3
7
Sample Output
YES
NO
Hint
Hint
X | Y means X is a factor of Y, for example 3 | 9;
X^2 means X multiplies itself, for example 3^2 = 9;
X*Y means X multiplies Y, for example 3*3 = 9.
这个题很题意很微妙啊
他的意思是给你一个数n 如果存在a b满足
若a,b为正整数,且n|a2b+1,则n|a2+b.
实际上的意思是如果存在 ab 满足第一个公式 但不满足第二个公式 那这个数就不满足性质p
这样推导出来的结果是 以下。。反正我数学差我看不懂
#include <bits/stdc++.h>
using namespace std;
#define INF 1e8
#define eps 1e-4
#define ll __int64
#define maxn 500010
#define mol 1000000007
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
if(240%n==0)printf("YES\n");
else printf("NO\n");
}
return 0;
}
第二种做法打表就可以了
#include <bits/stdc++.h>
using namespace std;
#define INF 1e8
#define eps 1e-4
#define ll __int64
#define maxn 50000+5
#define mol 1000000007
int flag[maxn];
void init(){
memset(flag,1,sizeof(flag));
for(int k=1;k<=5000;k++){
for(int i=1;i<=1000;i++){
for(int j=1;j<=1000;j++){
int x=i*i*j+1,y=i*i+j;
if(x%k==0&&y%k!=0){
flag[k]=0;
goto ed;
}
}
}
ed:{}
}
}
int main()
{
init();
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
if(flag[n])printf("YES\n");
else printf("NO\n");
}
return 0;
}