Problem Description
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.
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.
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 NOHintHint 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;因此,对于只满足前一个条件的n不符合#include<stdio.h> #include<math.h> #include<string.h> #define N 5005 int f[N]; void init() { int n,i,j,x,y; for(n=1;n<=5000;n++) { for(i=1;i<=1000;i++) { for(j=1;j<=1000;j++) { y=i*i*j+1; if(y%n==0) { y=i*i+j; if(y%n) { f[n]=1; break; } } } if(f[n]==1) break; } } } int main() { int t,n; memset(f,0,sizeof(f)); init(); scanf("%d",&t); while(t--) { scanf("%d",&n); if(f[n]) printf("NO\n"); else printf("YES\n"); } return 0; }