您的位置:首页 > 大数据 > 人工智能

HDU/HDOJ 2854 2009 Multi-University Training Contest 5 - Host by NUDT 数论

2011-09-21 14:41 211 查看

Central Meridian Number

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 210 Accepted Submission(s): 117



[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
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.

[align=left]Output[/align]
For each case, output “YES” if the given number is Kitty Number, “NO” if it is not.

[align=left]Sample Input[/align]

2
3
7


[align=left]Sample Output[/align]

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.


[align=left]Source[/align]
2009 Multi-University Training Contest 5 - Host by NUDT

其实是标题党。。
这货就是预处理一下就可以了。。纯暴力

我的代码:
#include<stdio.h>

bool flag[5005];

void init()
{
int i,j,n,x,y;
for(n=1;n<=5000;n++)
{
for(i=1;i<=1000;i++)
{
for(j=1;j<=1000;j++)
{
x=i*i*j+1;
y=i*i+j;
if(x%n==0)
{
if(y%n!=0)
{
flag
=true;
goto loop;
}
}
}
}
loop:;
}
}

int main()
{
int n,t;
init();
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(flag
)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐