結果

問題 No.36 素数が嫌い!
ユーザー tsushima
提出日時 2020-04-28 21:04:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 129 ms / 5,000 ms
コード長 1,192 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 196,404 KB
最終ジャッジ日時 2025-01-10 02:57:55
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

bool is_prime(ll num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrt_num = sqrt(num);
  for (ll i = 3; i <= sqrt_num; i += 2) {
    if (num % i == 0)
      return false;
  }

  return true;
}

vector<ll> prime_factor_oneline(ll n) {
  ll i = 2, tmp = n;
  vector<ll> res;
  while (i * i <= n) {
    if (tmp % i == 0) {
      tmp /= i;
      res.push_back(i);
    } else
      i++;
  }
  if (tmp != 1)
    res.push_back(tmp);
  return res;
}

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

  ll n;
  cin >> n;

  vector<ll> v = prime_factor_oneline(n);
  int siz = v.size();
  rep(i, 0, siz) {
    rep(j, i + 1, siz) {
      ll x = v[i] * v[j];
      if (x != n && n % x == 0) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
}
0