結果

問題 No.719 Coprime
ユーザー ありあり
提出日時 2023-02-09 22:26:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,471 bytes
コンパイル時間 917 ms
コンパイル使用メモリ 89,660 KB
実行使用メモリ 138,608 KB
最終ジャッジ日時 2023-09-21 04:20:47
合計ジャッジ時間 8,115 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 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 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,500 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 4 ms
4,380 KB
testcase_39 AC 6 ms
4,376 KB
testcase_40 AC 6 ms
4,380 KB
testcase_41 AC 115 ms
4,380 KB
testcase_42 AC 245 ms
4,376 KB
testcase_43 TLE -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cassert>
#include <cmath>
#include <bitset>
using namespace std;

vector<int> getPrimes(int n) {
  vector<bool> isPrime(n+1, true);
  for (int i = 2; i <= n; i++)
    if (isPrime[i])
      for (int j = i+i; j <= n; j += i)
        isPrime[j] = false;
  
  vector<int> primes;
  for (int i = 2; i <= n; i++)
    if (isPrime[i])
      primes.push_back(i);
  return primes;
}

vector<int> factorize(int n) {
  vector<int> res;
  for (int i = 2; i*i <= n; i++)
    if (n%i == 0) {
      while (n%i == 0)
        n /= i;
      res.push_back(i);
    }
  if (n != 1) res.push_back(n);
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<int> primes = getPrimes(n);
  vector<vector<int>> factotials(n+1);
  for (int i = 2; i <= n; i++) factotials[i] = factorize(i);
  //for (int i = 2; i <= n; i++) { cout << i << " : "; for (auto f : factotials[i]) cout << f << " "; cout << endl; }
  int m = primes.size();
  vector<int> dp(1<<m, 0);
  for (int s = 0; s < (1<<m); s++)
    for (int i = 2; i <= n; i++) {
      bool flag = true;
      int t = 0;
      for (auto f : factotials[i]) {
        int j = lower_bound(primes.begin(), primes.end(), f) - primes.begin();
        t += (1<<j);
        if (s&(1<<j)) flag = false;
      }
      if (flag) dp[s+t] = max(dp[s+t], dp[s] + i);
    }
  cout << dp[(1<<m)-1] << endl;
}
0