結果
問題 |
No.36 素数が嫌い!
|
ユーザー |
|
提出日時 | 2016-05-19 22:34:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 189 ms / 5,000 ms |
コード長 | 997 bytes |
コンパイル時間 | 1,245 ms |
コンパイル使用メモリ | 158,872 KB |
実行使用メモリ | 13,264 KB |
最終ジャッジ日時 | 2024-06-27 00:45:28 |
合計ジャッジ時間 | 5,492 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr) #define all(x) (x).begin(),(x).end() #define mp make_pair #define pb push_back #define fi first #define se second const int N=10000000; bool p[N+1]; bool inline prime(ll x) { for(ll i=2; i*i<=x; ++i) { if(x%i==0) return false; } return true; } bool valid(ll x) { fill(p,p+N+1,true); p[0]=p[1]=false; for(ll i=2; i<=N; ++i) { if(p[i]) for(ll j=2; i*j<=N; ++j) p[i*j]=false; } for(ll i=2; i*i<=x; ++i) { if(x%i==0) { if(!p[i]) return true; else { if(!prime(x/i)) return true; } } } return false; } int main() { ll n; cin >>n; string ans="NO"; if(valid(n)) ans="YES"; std::cout << ans << std::endl; return 0; }