結果

問題 No.1006 Share an Integer
ユーザー finefine
提出日時 2020-03-07 01:17:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 1,365 bytes
コンパイル時間 1,605 ms
コンパイル使用メモリ 166,520 KB
実行使用メモリ 26,624 KB
最終ジャッジ日時 2024-04-22 11:40:28
合計ジャッジ時間 3,910 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 92 ms
16,296 KB
testcase_12 AC 170 ms
25,284 KB
testcase_13 AC 183 ms
26,624 KB
testcase_14 AC 187 ms
26,496 KB
testcase_15 AC 153 ms
23,168 KB
testcase_16 AC 70 ms
13,120 KB
testcase_17 AC 91 ms
16,624 KB
testcase_18 AC 142 ms
23,488 KB
testcase_19 AC 138 ms
22,528 KB
testcase_20 AC 154 ms
23,936 KB
testcase_21 AC 171 ms
26,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;

    vector<int> is_prime(x, true);
    is_prime[0] = is_prime[1] = false;
    vector<int> min_fac(x, x);
    min_fac[0] = 0;
    min_fac[1] = 1;
    for (int i = 2; i < x; ++i) {
        if (!is_prime[i]) continue;
        min_fac[i] = i;
        for (int j = 2 * i; j < x; j += i) {
            is_prime[j] = false;
            if (min_fac[j] > i) min_fac[j] = i;
        }
    }

    vector<int> fs(x, 1);
    for (int i = 1; i < x; ++i) {
        int tmp = 1;
        int cur = i;
        int fac = 1;
        while (cur > 1) {
            if (min_fac[cur] == fac) {
                ++tmp;
            } else {
                fs[i] *= tmp;
                fac = min_fac[cur];
                tmp = 2;
            }
            cur /= min_fac[cur];
        }
        fs[i] *= tmp;
        fs[i] = i - fs[i];
    }

    int cnt = 1e9;
    vector<int> as;
    for (int a = 1; a < x; ++a) {
        int val = abs(fs[a] - fs[x - a]);
        if (val < cnt) {
            cnt = val;
            as.clear();
            as.push_back(a);
        } else if (val == cnt) {
            as.push_back(a);
        }
    }

    for (int a : as) {
        cout << a << " " << x - a << "\n";
    }
    return 0;
}
0