結果
問題 |
No.36 素数が嫌い!
|
ユーザー |
![]() |
提出日時 | 2020-02-28 21:15:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 107 ms / 5,000 ms |
コード長 | 1,253 bytes |
コンパイル時間 | 622 ms |
コンパイル使用メモリ | 82,916 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 16:35:02 |
合計ジャッジ時間 | 2,711 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <ctime> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define REP(i,n) for (int i = 0; i < (n); ++i) #define SORT(a) sort((a).begin(), (a).end()); #define UNIQ(a) SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end()); #define FIND(a,x) find((a).begin(), (a).end(), (x)) != (a).end() using namespace std; using ll = long long; using P = pair<int,int>; using namespace std; const int MOD = 1000000007; // 10^9 + 7 bool solve(ll n) { if (n <= 4) return false; ll lim = (ll)sqrt(n); vector<ll> primes, cnts; for (ll d = 2; d <= lim; d++) { int cnt = 0; while (n % d == 0) { cnt++; n /= d; } if (cnt > 0) { primes.push_back(d); cnts.push_back(cnt); } } if (n > 1) { primes.push_back(n); cnts.push_back(1); } if (primes.size() == 1 && cnts[0] <= 2) return false; if (primes.size() == 2 && cnts[0] == 1 && cnts[1] == 1) return false; return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; cout << (solve(N) ? "YES" : "NO") << endl; }