結果

問題 No.1006 Share an Integer
ユーザー bonKotsubonKotsu
提出日時 2021-06-21 22:13:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 166,556 KB
実行使用メモリ 10,848 KB
最終ジャッジ日時 2023-09-05 01:57:01
合計ジャッジ時間 5,201 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
10,668 KB
testcase_01 AC 79 ms
10,636 KB
testcase_02 AC 81 ms
10,700 KB
testcase_03 AC 80 ms
10,664 KB
testcase_04 AC 82 ms
10,548 KB
testcase_05 AC 82 ms
10,608 KB
testcase_06 AC 82 ms
10,656 KB
testcase_07 AC 79 ms
10,784 KB
testcase_08 AC 79 ms
10,668 KB
testcase_09 AC 79 ms
10,660 KB
testcase_10 AC 80 ms
10,636 KB
testcase_11 AC 84 ms
10,788 KB
testcase_12 AC 85 ms
10,848 KB
testcase_13 AC 86 ms
10,844 KB
testcase_14 AC 85 ms
10,612 KB
testcase_15 AC 85 ms
10,552 KB
testcase_16 AC 83 ms
10,788 KB
testcase_17 AC 84 ms
10,792 KB
testcase_18 AC 85 ms
10,720 KB
testcase_19 AC 85 ms
10,656 KB
testcase_20 AC 90 ms
10,620 KB
testcase_21 AC 86 ms
10,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

int main() {
  vector<int> v(2000005,1);
  for (int i = 2; i <= 2000000; i++) {
    for (int j = i; j <= 2000000; j += i) {
      v[j]++;
    }
  }
  int x;
  cin >> x;
  const int INF = 1001001001;
  int m = INF;

  auto calc = [&](int n) {
    return n - v[n];
  };

  for (int i = 1; i < x; i++) m = min(m, abs(calc(i)-calc(x-i)));
  for (int i = 1; i < x; i++) {
    if (abs(calc(i)-calc(x-i)) == m) cout << i << " " << x-i << endl;
  }


}
0