結果

問題 No.1006 Share an Integer
ユーザー iqueue02iqueue02
提出日時 2020-03-06 22:08:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 987 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 171,712 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2024-04-22 07:58:18
合計ジャッジ時間 5,312 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 TLE -
testcase_12 -- -
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;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;
vector<long long> divisor(long long n){
    vector<long long> res;
    for(long long i = 1; i*i <= n; i++){
        if(n%i==0){
            res.push_back(i);
            if(n/i != i)res.push_back(n/i);
        }
    }
    return res;
}

int main(){
  int x;
  cin >> x;
  set<P> st;
  int mx = INF;
  for (int a = 1; a + a <= x; a++) {
    int b = x - a;  
    auto d1 = divisor(a);
    auto d2 = divisor(b);
    int f1 = a - d1.size(), f2 = b - d2.size();
    int v = abs(f1 - f2);

    if (v < mx) {
      mx = v;
      st.clear();
      st.insert(make_pair(a, b));
      st.insert(make_pair(b, a));
    } else if (v == mx) {
      st.insert(make_pair(a, b));
      st.insert(make_pair(b, a));
    }
  }
  
  for (auto e : st) {
    cout << e.first << " " << e.second << endl;
  }
  return 0;
}
0