Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 5 Accepted Submission(s) : 4
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.< div>
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. [/hint]
题解:对于这道题目,Kitty 数满足给出任意A,B,必须同时满组 N | ((A^2)*B+1) Then N | (A^2+B) 才行,出现一个不成立就不正确。但是对于这道题目出现映射问题,具体思路要将不满足题意的标记,最后剩余的就是满足的熟,经过打表测试,发现只有21组合格数据。直接进行匹配即可。。。
#include<stdio.h>
#include<string.h>
int map[21]={1,2,3,4,5,6,8,10,12,15,16,20,24,30,40,48,60,80,120,240};
int main()
{
int a,b,i,j,n;
int x,y;
int mark;
// memset(map,0,sizeof(map));
// for(n=1;n<=250;n++)
// { mark=1;
// 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)
// {
// mark=0;
// map[n]=1;
// break;
// }
// }
// }
// if(mark==0)
// break;
// }
// }
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int mark=0;
for(int i=0;i<21;i++)
{
if(map[i]==n)
{
mark=1;
break;
}
}
if(!mark)
{
printf("NO\n");
}
else
{
printf("YES\n");
}
}
return 0;
}