Moscow subregional problem H. hometask conversion, prime number screening

Source: Internet
Author: User

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

Moscow Subregional 2010


My Solution

Prime number Screening

First, n^2 is divisible by n!.

i.e. N is (N-1)! Divisible

Arbitrarily basically as long as N is not a prime number can have a constraint other than N and 1,

So as long as the prime number is NO

Also for 4 because only 1 2 4 so the number of pages does not meet N is (N-1)! divisible, so 4 special treatment no//good caution, by the way, or 4 of special treatment may have to WA and later found

0! is 1 so N = = 1 also satisfies 1^1 is divisible by 1 YES

Complexity O (sqrt (n))

The code was implemented by the teammates, so the AC code was cs_lyj1997 to the teammate.

In addition we have also had another 2 questions, but that 2 questions, the author did not participate, so do not tidy up


#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 problem H. hometask conversion, prime number screening

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.