結果

問題 No.1006 Share an Integer
ユーザー MayimgMayimg
提出日時 2020-03-07 05:39:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 908 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 201,584 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-04-22 11:52:14
合計ジャッジ時間 11,112 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 479 ms
11,904 KB
testcase_12 AC 853 ms
17,988 KB
testcase_13 AC 908 ms
18,816 KB
testcase_14 AC 902 ms
18,816 KB
testcase_15 AC 765 ms
16,640 KB
testcase_16 AC 348 ms
9,652 KB
testcase_17 AC 492 ms
12,288 KB
testcase_18 AC 766 ms
16,640 KB
testcase_19 AC 734 ms
16,128 KB
testcase_20 AC 795 ms
17,160 KB
testcase_21 AC 900 ms
18,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> sieve (int n) {
  vector<int> res(n + 1);
  iota(res.begin(), res.end(), 0);
  for (int i = 2; i <= n; i++) {
    if (res[i] != i) continue;
    for (int j = i + i; j <= n; j += i) {
      res[j] = i;
    }
  }
  return res;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int x;
  cin >> x;
  auto table = sieve(x);
  vector<int> cnt(x + 1);
  auto f = [&] (int k) {
    long long kk = k;
    vector<int> appear;
    while (k > 1) {
      cnt[table[k]]++;
      appear.push_back(table[k]);
      k /= table[k];
    }
    long long res = 1;
    for (int i : appear) {
      if (cnt[i] > 0) {
        res *= cnt[i] + 1;
        cnt[i] = 0;
      }
    }
    return kk - res;
  };
  long long mi = 1 << 30;
  for (int i = 1; i <= x / 2; i++) mi = min(mi, abs(f(i) - f(x - i)));
  vector<pair<int, int>> ans;
  for (int i = 1; i <= x; i++) if (abs(f(i) - f(x - i)) == mi) ans.emplace_back(i, x - i);
  for (auto& p : ans) {
    cout << p.first << " " << p.second << '\n';
  }
  return 0;
}
0