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;
}