結果

問題 No.1006 Share an Integer
ユーザー batsumarubatsumaru
提出日時 2020-03-06 22:46:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 169,960 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-04 12:23:37
合計ジャッジ時間 3,208 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 52 ms
4,380 KB
testcase_12 AC 69 ms
4,376 KB
testcase_13 AC 72 ms
4,376 KB
testcase_14 AC 71 ms
4,376 KB
testcase_15 AC 66 ms
4,376 KB
testcase_16 AC 46 ms
4,376 KB
testcase_17 AC 55 ms
4,380 KB
testcase_18 AC 66 ms
4,376 KB
testcase_19 AC 65 ms
4,380 KB
testcase_20 AC 67 ms
4,376 KB
testcase_21 AC 69 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int countDivisors(int i){
  int cnt = 0;
  for(int j=1; j*j <=i; j++){
    if(i%j!=0){
      continue;
    }
    if(j*j==i){
      cnt++;
      break;
    }
    cnt += 2;
  }
  return cnt;
}

int main() {
  int x;
  cin >> x;
  vector<int> ans;
  int mini = 1e9;
  for(int i=x/2; x/2-i<=10000 && i>=1; i--){
    int d1 = countDivisors(i);
    int d2 = countDivisors(x-i);
    int score = abs(i-d1-(x-i-d2));
    if(score < mini){
      mini = score;
      ans.clear();
      ans.push_back(i);
    }else if(score == mini){
      ans.push_back(i);
    }
  }
  sort(ALL(ans));

  REP(i,SZ(ans)){
      printf("%d %d\n", ans[i], x-ans[i]);
  }
  IREP(i,SZ(ans)){
      if(ans[i] == x-ans[i]){
        continue;
      }
      printf("%d %d\n", x-ans[i], ans[i]);
  }
}
0