結果

問題 No.1006 Share an Integer
ユーザー あるふぁあるふぁ
提出日時 2020-03-06 22:00:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 177,592 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-04 09:53:59
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int func_v(int n) {
    map<int, int> m;

    int t = n;

    int i = 2;
    while (i * i <= n) {
        if (n % i == 0) {
            m[i]++;
            n /= i;
        }
        else {
            i++;
        }
    }
    if (n > 1) m[n]++;

    int res = 1;

    for (auto&& p : m) {
        res *= p.second + 1;
    }

    return t - res;
}

int main() {
    int x;
    cin >> x;

    int o = x / 2;

    vector<pint> res;

    int m = INF;

    for (int a = max(1, o - 1000); a <= min(o + 1000, x-1); a++) {
        int b = x - a;
        int fa = func_v(a);
        int fb = func_v(b);
        m = min(m, abs(fa - fb));
    }

    for (int a = max(1, o - 1000); a <= min(o + 1000, x-1); a++) {
        int b = x - a;
        int fa = func_v(a);
        int fb = func_v(b);
        if (abs(fa - fb) == m) {
            res.push_back(make_pair(a, b));
        }
    }

    sort(all(res));

    int s = res.size();

    rep(i, s) cout << res[i].first << " " << res[i].second << endl;
    return 0;
}
0