Moscow Subregional 2010 Problem H. Hometask 转化、素数筛选

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

时间: 2024-10-11 23:41:56

Moscow Subregional 2010 Problem H. Hometask 转化、素数筛选的相关文章

Moscow Subregional 2010 Problem A. Alien Visit 计算几何、连续圆的总面积

ACM ICPC 2010-2011 NEERC Moscow Subregional Contest Moscow, October 24, 2010 Problem A. Alien Visit Time limit: 1 second Memory limit: 256 megabytes 25 May, 1997, near Elcino-Borisovo place, Jandal region, strange signs were found in the field... Wit

Moscow Subregional 2010 Problem K. KMC Attacks 交互题、队列优化、枚举

ACM ICPC 2010-2011 NEERC Moscow Subregional Contest Moscow, October 24, 2010 Problem K. KMC Attacks Time limit: 2 seconds Memory limit: 256 megabytes Warrant VI is a remote planet located in the Koprulu Sector. Warrant VI features a strange huge fiel

2014-2015 ACM-ICPC, NEERC, Eastern Subregional Contest Problem H. Pair: normal and paranormal

题目链接:http://codeforces.com/group/aUVPeyEnI2/contest/229669 时间限制:1s 空间限制:64MB 题目大意:给定一个长度为2n,由n个大写字母和n小写字母组成的字符串,将对应的字母两两连接,且不相交,按顺序输出没个大写字母对应的小写字母的位置,如果不存在则输出"Impossible" 样例: /home/destr/Desktop/深度截图_选择区域_20181006175058.png /home/destr/Desktop/深

[email&#160;protected] Sieve of Eratosthenes (素数筛选算法) &amp; Related Problem (Return two prime numbers )

Sieve of Eratosthenes (素数筛选算法) Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. For example, if n is 10, the output should be “2, 3, 5, 7″. If n is 20, the output should be “2, 3, 5, 7, 11, 13,

Problem H. The Fence

/** 题目:Problem H. The Fence 链接:https://vjudge.net/problem/Gym-101090H 题意:给定一个字符串,只有0或者1: 问:假如两个不同的1之间的0,1数量是k的倍数(包括0倍)则输出这两个1的位置: 思路:%k:直到遇到两个相同的余数,说明之间的01数量为k的倍数. */ #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1

Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description In a Famous TV Show “Find Out” there are n characters and only one Horrible Truth. To make the series breathtaking all way long, the sc

Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description Andrew is having a hard time preparing his 239-th contest for Petrozavodsk. This time the solution to the problem is based on Di

ZCMU Problem H: Crixalis&#39;s Equipment(贪心,排序)

#include<stdio.h> #include<stdlib.h> struct node { int a,b; }c[1002]; int cmpxy(const struct node *c,const struct node *d) { return (d->b - d->a) - (c->b - c->a); } int main() { int n,i,v,t,flag; // freopen("a.txt","

实验12:Problem H: 整型数组运算符重载

Home Web Board ProblemSet Standing Status Statistics Problem H: 整型数组运算符重载 Problem H: 整型数组运算符重载 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 643  Solved: 401[Submit][Status][Web Board] Description 定义Array类: 1.拥有数据成员int length和int *mems,分别是数组中元素的个数和元