結果

問題 No.1006 Share an Integer
ユーザー StrorkisStrorkis
提出日時 2020-03-06 22:40:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 695 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 77,156 KB
実行使用メモリ 10,760 KB
最終ジャッジ日時 2023-08-04 12:14:05
合計ジャッジ時間 2,417 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 37 ms
7,340 KB
testcase_12 AC 68 ms
10,552 KB
testcase_13 AC 74 ms
10,700 KB
testcase_14 AC 73 ms
10,740 KB
testcase_15 AC 70 ms
9,752 KB
testcase_16 AC 27 ms
6,392 KB
testcase_17 AC 40 ms
7,444 KB
testcase_18 AC 66 ms
9,828 KB
testcase_19 AC 58 ms
9,572 KB
testcase_20 AC 64 ms
10,040 KB
testcase_21 AC 72 ms
10,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
using namespace std;
using P = pair<int, int>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int X; cin >> X;
  vector<int> a(X, 1);
  for (int i = 2; i <= X; i++)
    for (int n = i; n <= X; n += i) a[n]++;

  auto f = [&](int n) { return n - a[n]; };
  
  set<P> s;
  int minfn = X;
  for (int n = 1; n <= X / 2; n++) {
    int fn = abs(f(n) - f(X-n));
    if (minfn > fn) {
      minfn = fn;
      s.clear();
      s.insert(P(n, X-n));
      s.insert(P(X-n, n));
    }
    else if (minfn == fn) {
      s.insert(P(n, X-n));
      s.insert(P(X-n, n));
    }
  }

  for (P p : s) cout << p.first << " " << p.second << "\n";
}
0