結果

問題 No.36 素数が嫌い!
ユーザー alpha_virginisalpha_virginis
提出日時 2016-08-23 01:56:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 2,246 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 55,768 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 07:40:46
合計ジャッジ時間 1,723 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 24 ms
4,376 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 10 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 9 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdint>
#include <vector>
#include <tuple>
#include <cassert>

namespace Wheel {
  static constexpr uint64_t miniprimes[] = {2, 3, 5, 7, 11, 13};
  static std::vector<int> diff;
  struct Initializer {
    Initializer() {
      uint64_t prev = 17;
      for(uint64_t i = 17 + 1; i <= 17 + 2 * 3 * 5 * 7 * 11 * 13; ++i) {
        auto checker = [](uint64_t i){
          for(uint64_t p : miniprimes) {
            if( i % p == 0 ) return true;
          }
          return false;
        };
        if( checker(i) ) continue;
        diff.push_back(i - prev);
        prev = i;
      }
    }
  } initializer;
  static bool isprime(uint64_t x) {
    for(uint64_t p : miniprimes) {
      if( p == x ) return true;
      if( x % p == 0 ) return false;
    }
    assert( x >= 17 );
    for(uint64_t p = 17;;) {
      for(std::size_t k = 0; k < diff.size(); ++k) {
        if( x == p ) return true;
        if( x % p == 0 ) return false;
        p += diff[k];
        if( p >= (1ULL << 32) ) return true;
        if( p * p > x ) return true;
      }
    }
    return true;
  }
  static std::vector< std::tuple<uint64_t, int> > primeFactors(uint64_t x) {
    std::vector< std::tuple<uint64_t, int> > res;
    for(uint64_t p : miniprimes) {
      int count = 0;
      while( x % p == 0 ) {
        x /= p;
        count += 1;
      }
      if( count != 0 ) {
        res.push_back(std::make_tuple(p, count));
      }
    }
    for(uint64_t p = 17;;) {
      for(std::size_t k = 0; k < diff.size(); ++k) {
        int count = 0;
        while( x % p == 0 ) {
          x /= p;
          count += 1;
        }
        if( count != 0 ) {
          res.push_back(std::make_tuple(p, count));
        }
        if( x == 1 ) goto label_1;
        p += diff[k];
        if( p >= (1ULL << 32) ) goto label_1;
        if( p * p > x ) goto label_1;
      }
    }
  label_1:;
    if( x != 1 ) {
      res.push_back(std::make_tuple(x, 1));
    }
    return res;
  }
};
#include <cstdio>

int main() {

  uint64_t n;
  scanf("%lu", &n);
  auto res = Wheel::primeFactors(n);
  int count = 0;
  for(auto x : res) {
    // printf("%lu, %d\n", std::get<0>(x), std::get<1>(x));
    count += std::get<1>(x);
  }
  puts(count >= 3 ? "YES" : "NO");
  
  return 0;
}
0