杭电 2854Central Meridian Number 完全不懂的数论

         此题真乃是数论中的acm,acm中的数论,神题!!!!!!!!!一大堆神马公式的,最后推出来一个特神的公式,完全看不懂,弱爆了。。。。。。。题目:

Central Meridian Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 254    Accepted Submission(s): 143


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.
 

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
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.
ac代码:

//判断给定的正整数n是否满足以下性质P:
//若a,b为正整数,且n|a2b+1,则n|a2+b.
//性质Q:
//若a为正整数,且(a,n) = 1,则n | a4 – 1.
//
//费马小定理:
//若m为质数,a∈Z,(a,m) = 1,则am-1 ≡ 1(mod m).
//
//Be’zout定理:
//若a,b是整数,且(a,b) = d,那么对于任意给定的整数x,y,ax + by 都一定是d的倍数,特别地,一定存在整数x,y,使得 ax + by = d 成立.
//性质P→性质Q:
//
//若n具有性质P
//则对于任意a∈N*,若(a,n) = 1,由Be’zout定理可知存在b∈N*,使n|a2b+1.
//利用性质P,则有n|a2+b,
//                   而a4–1=a2(a2+b)–(a2b+1),故n|a4–1.
//于是n具有性质Q.
//性质Q→性质P:
//若n具有性质Q
//这时,若a,b∈N*,使得n|a2b+1,则(a,n) = 1.
//
//利用性质Q,可知n|a4–1,于是,由
//
//                   a2(a2+b)=(a4–1)+(a2b+1)
//
//         有n|a2(a2+b),而(a,n) = 1,故n|a2+b.
//于是n具有性质P.
//
//注意到
//当a为奇数时,因为a4 - 1 = (a2 – 1)(a2 + 1),而 奇数的平方≡1(mod 8),又a2 + 1为偶数,故有16 | a4 – 1.
//当(a,3) = 1时,a2 ≡ 1(mod 3),故3 | a4 – 1.
//当(a,5) = 1时,由费马小定理,5 | a4 – 1.
//这表明:如果n | 240,并且n∈N*,则 n 具有性质Q.
//反过来
//设n∈N*,n 具有性质Q,并设 n = 2tk,这里 k 为奇数. 若 k > 1,则 (k – 2,n) = 1,由性质Q可知 n | (k – 2)4 – 1,从而 k | (k – 2)4 – 1.
//
//但是因为 (k – 2)4 ≡ ( – 2)4 ≡16(mod k),故 k | 15. 这时,(11,n) = 1,利用性质Q,可知 n | 114 – 1,所以,2t | 114 – 1,故 t ≤ 4. 这表明 n | 240. 
//综上所述,当且仅当 n | 240,n∈N*时,n具有性质P
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int ncase;
	scanf("%d",&ncase);
	int num;
	while(ncase--){
	  scanf("%d",&num);
	  if(!(240%num))
		  printf("YES\n");
	  else
		  printf("NO\n");
	}//while
  return 0;
}//main


你可能感兴趣的:(Integer,input,each,output)