結果

問題 No.1006 Share an Integer
ユーザー kibunakibuna
提出日時 2020-03-06 21:45:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,230 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 174,384 KB
実行使用メモリ 18,824 KB
最終ジャッジ日時 2024-04-22 05:51:31
合計ジャッジ時間 2,864 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 12 ms
11,972 KB
testcase_12 AC 15 ms
18,000 KB
testcase_13 AC 15 ms
18,824 KB
testcase_14 AC 15 ms
18,772 KB
testcase_15 AC 15 ms
16,604 KB
testcase_16 AC 11 ms
9,796 KB
testcase_17 AC 13 ms
12,288 KB
testcase_18 AC 14 ms
16,688 KB
testcase_19 AC 13 ms
16,132 KB
testcase_20 AC 15 ms
16,980 KB
testcase_21 AC 15 ms
18,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

// list up all factors
template <typename T>
set<T> factors(T a) {
    set<T> facs;
    for (T i = 1; i * i <= a; ++i) {
        if (a % i == 0) {
            facs.insert(i);
            facs.insert(a / i);
        }
    }
    return facs;
}

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint x;
    cin >> x;
    vector<lint> f(x + 1);
    for (int i = max(1LL, x / 2 - 1000); i < min(x, x / 2 + 1000); ++i) {
        f[i] = i - factors(i).size();
    }
    vector<pair<int, int>> ret;
    lint mini = inf;
    for (int i = max(1LL, x / 2 - 1000); i < min(x, x / 2 + 1000); ++i) {
        chmin(mini, abs(f[i] - f[x - i]));
    }
    for (int i = max(1LL, x / 2 - 1000); i < min(x, x / 2 + 1000); ++i) {
        if (abs(f[i] - f[x - i]) == mini)
            ret.emplace_back(i, x - i);
    }
    for (auto &r : ret) {
        cout << r.first << " " << r.second << "\n";
    }
    return 0;
}
0