結果

問題 No.1006 Share an Integer
ユーザー batsumarubatsumaru
提出日時 2020-03-06 22:37:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,149 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 164,484 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-22 09:45:18
合計ジャッジ時間 7,566 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,140 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,812 KB
testcase_03 AC 2 ms
6,820 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

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=1; 2*i <=x; 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);
    }
  }

  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