Discription
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
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.
题意
我觉得这个题意可能有点问题。
给你一个数,如果能找出两个数a,b使得这三个数满足式子N | ((A^2)*B+1)
,但不满足式子N | (A^2+B)
,那么这个数n是符合要求的数,输出YES。
按照上面那种理解是能过的。
思路
由于找不到规律就这届暴力打表了。
AC代码
#include<bits/stdc++.h>
using namespace std;
int t;
int n;
int f[5001];
/*void init()
//打表找规律的函数
{
for(int i=1; i<=5000; i++)
{
for(int j=1; j<=1000; j++)
{
for(int k=1; k<=1000; k++)
{
if((j*j*k+1)%i==0&&(j*j+k)%i!=0)
{
f[i]=1;
break;
}
}
if(f[i]==1)
break;
}
}
for(int i=1;i<=5000;i++)
if(f[i]==0)
cout<<i<<endl;
}*/
void init()
{
//打完表之后发现成立的就这些数。
f[1]=1;
f[2]=1;
f[3]=1;
f[4]=1;
f[5]=1;
f[6]=1;
f[8]=1;
f[10]=1;
f[12]=1;
f[15]=1;
f[16]=1;
f[20]=1;
f[24]=1;
f[30]=1;
f[40]=1;
f[48]=1;
f[60]=1;
f[80]=1;
f[120]=1;
f[240]=1;
}
int main()
{
init();
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(f[n]==1)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}