【HDU - 2854】Central Meridian Number (暴力打表)

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使得这三个数满足式子1,但不满足式子2,那么这个数n就不是符合要求的数,输出NO

思路:

一开始以为要找同时满足两个式子的数,后来发现不是,暴力打表,发现到240就没了。。。

一个有推导过程的博客

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
int ok(int x)
{
	for(int i=1;i<=1000;i++)
	{
		for(int j=1;j<=1000;j++)
		{
			if((i*i*j+1)%x==0&&((i*i+j)%x!=0))
			return 0;
		}
	}
	return 1;
}
map<int,int> mp;
int main()
{
//	for(int i=1;i<=1000;i++)//打表部分
//	{
//		if(ok(i))
//		{
//			printf("mp[%d]=1; \n",i);
//		}
//	}
	mp[1]=1;
	mp[2]=1;
	mp[3]=1;
	mp[4]=1;
	mp[5]=1;
	mp[6]=1;
	mp[8]=1;
	mp[10]=1;
	mp[12]=1;
	mp[15]=1;
	mp[16]=1;
	mp[20]=1;
	mp[24]=1;
	mp[30]=1;
	mp[40]=1;
	mp[48]=1;
	mp[60]=1;
	mp[80]=1;
	mp[120]=1;
	mp[240]=1;
	int t,a,b;
	cin>>t;
	while(t--)
	{
		scanf("%d",&a);
		if(mp[a]==1)
		puts("YES");
		else
		puts("NO");
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值