結果

問題 No.414 衝動
ユーザー alpha_virginisalpha_virginis
提出日時 2016-08-27 16:29:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 2,187 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 174,820 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 08:23:31
合計ジャッジ時間 2,209 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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;
  }
  // x >= 2
  static std::vector< std::tuple<uint64_t, int> > primeFactors(uint64_t x) {
    assert( x != 0 and x != 1 );
    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;
  }
};

int main() {
  uint64_t x;
  scanf("%lu", &x);
  if( x == 1 ) {
    printf("1 1\n");
    return 0;
  }
  auto factors = Wheel::primeFactors(x);
  auto y = std::get<0>(factors[0]);
  printf("%lu %lu\n", y, x / y);
  
  return 0;
}

0