結果

問題 No.1006 Share an Integer
ユーザー StrorkisStrorkis
提出日時 2020-03-06 22:40:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 695 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 77,300 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-22 09:50:12
合計ジャッジ時間 3,000 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 51 ms
7,552 KB
testcase_12 AC 142 ms
10,496 KB
testcase_13 AC 145 ms
11,008 KB
testcase_14 AC 149 ms
10,880 KB
testcase_15 AC 101 ms
9,984 KB
testcase_16 AC 35 ms
6,528 KB
testcase_17 AC 46 ms
7,680 KB
testcase_18 AC 115 ms
9,856 KB
testcase_19 AC 89 ms
9,728 KB
testcase_20 AC 127 ms
10,368 KB
testcase_21 AC 197 ms
10,880 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