Moscow Subregional 2010 Problem H. Hometask 轉化、素數篩選

來源:互聯網
上載者: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

素數篩選

首先 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 轉化、素數篩選

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.