結果

問題 No.36 素数が嫌い!
コンテスト
ユーザー sahiya
提出日時 2021-03-02 19:47:48
言語 C++14
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,705 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,036 ms
コンパイル使用メモリ 143,880 KB
実行使用メモリ 9,272 KB
最終ジャッジ日時 2026-07-08 03:01:13
合計ジャッジ時間 2,896 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;
struct edge {
    int to, cost, id;
};
const double EPS = 1E-09;
const ll MOD = 1E+09 + 7; // =998244353;
const ll INF = 1E18;
const int MAX_N = 1E+05;

ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 };

ll N;

map<ll, ll> prime_factor(ll n);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;

    auto res = prime_factor(N);

    bool ans = true;
    if (res.size() == 2) {
        ans = !all_of(res.begin(), res.end(), [](pair<ll, ll> p) { return p.second == 1; });
    } else if (res.size() == 1) {
        if (res.begin()->second <= 2)
            ans = false;
    } else if (res.size() == 0) {
        ans = false;
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << (ans ? "YES" : "NO") << "\n";

    return 0;
}

//素因数分解
map<ll, ll> prime_factor(ll n)
{
    map<ll, ll> mp;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }
    if (n != 1)
        mp[n] = 1;
    return mp;
}
0