zoukankan      html  css  js  c++  java
  • 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem H. Hometask 水题

    Problem H. Hometask

    题目连接:

    http://codeforces.com/gym/100714

    Description

    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 N2
    .

    Input

    The first line of input contains the only integer N (1 ≤ N ≤ 109
    ).

    Output

    Please, print to output “YES” provided that N! is divisible by N2
    , otherwise print “NO”.

    Sample Input

    3

    Sample Output

    NO

    Hint

    题意

    问你n!%n^2 == 0?

    题解:

    暴力分解N的质因数就好了,然后看一看就好了……

    代码

    #include <bits/stdc++.h>
    #define rep(a,b,c) for(int (a)=(b);(a)<=(c);++(a))
    #define drep(a,b,c) for(int (a)=(b);(a)>=(c);--(a))
    #define pb push_back
    #define mp make_pair
    #define sf scanf
    #define pf printf
    #define two(x) (1<<(x))
    #define clr(x,y) memset((x),(y),sizeof((x)))
    #define dbg(x) cout << #x << "=" << x << endl;
    const int mod = 1e9 + 7;
    int mul(int x,int y){return 1LL*x*y%mod;}
    int qpow(int x , int y){int res=1;while(y){if(y&1) res=mul(res,x) ; y>>=1 ; x=mul(x,x);} return res;}
    inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
    using namespace std;
    const int maxn = 1e5 + 50;
    
    int pre[maxn] , prime[maxn] , priemlen;
    vector < int > vi;
    map < int , int > fac;
    
    void init(){
        for(int i = 2 ; i < maxn ; ++ i) if(!pre[i]){
    		prime[priemlen ++ ] = i;
    		for(int j = i ; j < maxn ; j += i )pre[j] = i;
    	}
    }
    
    void dfs( int x , int y ){
    	if( x < maxn ){
    		while( x > 1 ){
    			vi.pb( pre[x] ) ;
    			x /= pre[x];
    		}
    	}else{
    		for( int i = y ; ; ++ i) if( x % prime[i] == 0 ){
    			vi.pb( prime[i] );
    			dfs( x / prime[i] , i );
    			return ;
    		}else if( 1LL * prime[i] * prime[i] > x ) break;
    		vi.pb( x );
    	}
    }
    
    bool judge( int N ){
    	vi.clear();
    	fac.clear();
    	dfs( N , 0 );
    	sort( vi.begin() , vi.end() );
    	for(auto it : vi) fac[it] ++ ;
    	for(auto it : fac){
    		int v = it.first , num = it.second;
    		if( ( N - 1 ) / v < num )  return false;
    	}
    	return true;
    }
    
    bool baoli( int N ){
    	int x = 1 ;
    	for(int i = 1 ; i < N ; ++ i) x = x * i % N;
    	return x == 0;
    }
    
    int main(int argc,char *argv[]){
    	int N;
    	cin >> N;
    	init();
    	if(N == 1) cout << "YES" << endl;
    	else{
    		if( judge( N ) ) cout << "YES" << endl;
    		else cout << "NO" << endl;
    	}
    
    	return 0;
    }
  • 相关阅读:
    拥有自己的代码生成器—Newlife.XCode模板编写教程
    基于Newlife.XCode的权限系统(含数据集权限)【设计篇】
    拥有自己的代码生成器—NewLife.XCode代码生成器分析
    利用javascript来转换GB2312到UNICONDE &#形式
    和荣笔记 从 Unicode 到 GB2312 转换表制作程式
    如何做SVN迁移
    和荣笔记 GB2312 字符集和编码说明
    asp对象化之:基于adodb.stream的文件操作类
    Unicode 汉字内码表
    微软建议的ASP性能优化28条守则 之三
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5752174.html
Copyright © 2011-2022 走看看