結果

問題 No.36 素数が嫌い!
ユーザー 久我山菜々久我山菜々
提出日時 2018-11-19 22:31:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 826 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 84,080 KB
実行使用メモリ 10,220 KB
最終ジャッジ日時 2023-08-26 02:08:06
合計ジャッジ時間 4,169 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
8,872 KB
testcase_01 AC 72 ms
9,540 KB
testcase_02 AC 71 ms
9,224 KB
testcase_03 AC 73 ms
8,732 KB
testcase_04 AC 71 ms
9,164 KB
testcase_05 AC 81 ms
8,884 KB
testcase_06 AC 75 ms
9,680 KB
testcase_07 AC 79 ms
8,928 KB
testcase_08 AC 72 ms
8,636 KB
testcase_09 AC 73 ms
8,640 KB
testcase_10 AC 76 ms
8,560 KB
testcase_11 AC 82 ms
9,808 KB
testcase_12 AC 80 ms
8,684 KB
testcase_13 AC 88 ms
9,016 KB
testcase_14 AC 75 ms
8,932 KB
testcase_15 AC 71 ms
8,636 KB
testcase_16 AC 74 ms
8,968 KB
testcase_17 AC 82 ms
9,228 KB
testcase_18 AC 72 ms
10,220 KB
testcase_19 AC 72 ms
9,976 KB
testcase_20 AC 73 ms
9,016 KB
testcase_21 AC 73 ms
8,928 KB
testcase_22 AC 72 ms
9,008 KB
testcase_23 AC 72 ms
8,728 KB
testcase_24 AC 73 ms
8,672 KB
testcase_25 AC 74 ms
8,900 KB
testcase_26 AC 77 ms
8,936 KB
testcase_27 AC 78 ms
9,180 KB
testcase_28 AC 78 ms
9,196 KB
testcase_29 AC 79 ms
8,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<bitset>

static int const MAX = 10000000 + 1;

std::vector<int> primes() {
  std::vector<int> rs;
  std::bitset<MAX> ps;
  ps.set();
  ps[0] = ps[1] = 0;
  for(int i{2}; i < MAX; ++i) {
    if(!ps[i]) continue;

    rs.push_back(i);
    for(int j{i * 2}; j < MAX; j += i) {
      ps[j] = 0;
    }
  }
  return rs;
}

bool ok(std::vector<int> const& ps, long long n, int depth) {
  for(auto e: ps) {
    if(n == e) {
      return false;
    }
    if(n % e == 0) {
      if(depth > 0) return true;
      return ok(ps, n / e, 1);
    }
  }
  return false;
}

int main(int, char**) {
  long long n;
  std::cin >> n;

  auto ps = primes();
  if(!ok(ps, n, 0)) {
    std::cout << "NO" << std::endl;
  } else {
    std::cout << "YES" << std::endl;
  }
}
0