結果

問題 No.1006 Share an Integer
ユーザー pekempeypekempey
提出日時 2020-03-06 21:36:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 1,823 ms
コンパイル使用メモリ 170,232 KB
実行使用メモリ 10,776 KB
最終ジャッジ日時 2023-08-04 07:24:32
合計ジャッジ時間 3,542 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 36 ms
7,588 KB
testcase_12 AC 82 ms
10,488 KB
testcase_13 AC 86 ms
10,700 KB
testcase_14 AC 86 ms
10,740 KB
testcase_15 AC 67 ms
9,772 KB
testcase_16 AC 27 ms
6,248 KB
testcase_17 AC 37 ms
7,464 KB
testcase_18 AC 68 ms
9,696 KB
testcase_19 AC 62 ms
9,680 KB
testcase_20 AC 74 ms
9,920 KB
testcase_21 AC 87 ms
10,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
  int X; cin >> X;
  vector<int> cnt(X + 1);
  for (int i = 1; i <= X; i++) {
    for (int j = i; j <= X; j += i) {
      cnt[j]++;
    }
  }
  auto f = [&](int x) {
    return x - cnt[x];
  };
  int ans = INT_MAX;
  vector<pair<int, int>> pairs;
  for (int i = 1; i <= X - 1; i++) {
    int j = X - i;
    int cost = abs(f(i) - f(j));
    if (ans > cost) {
      ans = cost;
      pairs.clear();
      pairs.emplace_back(i, j);
    } else if (ans == cost) {
      pairs.emplace_back(i, j);
    }
  }
  for (auto p : pairs) {
    cout << p.first << ' ' << p.second << '\n';
  }
}
0