博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
又是打表找规律
阅读量:3952 次
发布时间:2019-05-24

本文共 1672 字,大约阅读时间需要 5 分钟。

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

237

Sample Output

YESNO

Hint

HintX | 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.

【思路】

打表:

#include 
#include
using namespace std;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<
<

正式代码:

#include
using namespace std;int t;int n;int f[5001];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(); ios::sync_with_stdio(false); cin>>t; while(t--) { cin>>n; if(f[n]==1) cout<<"YES"<

 

转载地址:http://lpyzi.baihongyu.com/

你可能感兴趣的文章
shell的dirname $0和readlink用法
查看>>
设计模式——设计模式三大分类以及六大原则
查看>>
Android开发——ListView局部刷新的实现
查看>>
Android开发——ListView的复用机制源码解析
查看>>
Android开发——架构组件LiveData源码解析
查看>>
IDEA常用快捷键整理
查看>>
【Vue】两个元素同一行显示
查看>>
XXL-Job使用
查看>>
如何在SwaggerAPI中添加统一授权认证
查看>>
多线程
查看>>
【Linux】Centos7 常用命令
查看>>
【Redis】Centos7下安装Redis
查看>>
【Redis】Centos7下搭建Redis集群
查看>>
【Redis】Centos7下搭建Redis集群——哨兵模式
查看>>
【Linux】本地ping不同VM虚拟机
查看>>
【SpringCloud】Hystrix
查看>>
乐观锁、悲观锁、公平锁、可重入锁
查看>>
快速阅读——《认知篇》
查看>>
【C#】返回值为DataTable的数据
查看>>
【Asp.net】基本概念
查看>>