标签:
ACM ICPC 2010-2011 NEERC Moscow Subregional Contest Moscow, October 24, 2010
Problem H. Hometask
Time limit: 1 second
Memory limit: 256 megabytes
Kolya is still trying to pass a test on Numbers Theory. The lecturer is so desperate about Kolya’s
knowledge that she gives him the same task every time.
The problem is to check if N! is divisible by N^2.
Input
The first line of input contains the only integer N (1 ≤ N ≤ 10^9).
Output
Please, print to output “YES” provided that N! is divisible by N2, otherwise print “NO”.
Examples
stdin stdout
3 NO
9 YES
Note
N! = 1 · 2 · . . . · N
Source
My Solution
素数筛选
首先 N^2 被 N!整除也就是 N 被 (N - 1)! 整除
随意基本上 只要 N不是素数 就可以有除了 N 和 1以外的约束,
所以只要 是素数就是 NO
此外 对于 4 由于 只有 1 2 4所以页数不满足 N 被 (N - 1)!整除, 所以4特殊处理 NO //还好谨慎,顺便打了个表, 不然4的特殊处理可能要WA了以后再发现
0! 是 1 所以 N == 1也满足 1^1 被 1整除 YES
复杂度 O(sqrt(n))
比赛的时候代码是队友实现的, 所以向队友 CS_LYJ1997 要了AC代码
此外我们对还过了另外2题, 但那2题, 笔者没有参与,所以就不整理上来了
#include<iostream> #include<cmath> using namespace std; int main() { int n,i; bool f; f=false; cin>>n; for(i=2;i<=sqrt(n);i++) if (n%i==0) f=true; if (n==1) f=true; if (!f || n==4) cout<<"NO"<<endl; else cout<<"YES"<<endl; return 0; }
Thank you!
------from ProLights
Moscow Subregional 2010 Problem H. Hometask 转化、素数筛选
标签:
原文地址:http://blog.csdn.net/prolightsfxjh/article/details/52157837