結果

問題 No.1006 Share an Integer
ユーザー kibunakibuna
提出日時 2020-03-06 21:42:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,227 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 172,648 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-04-22 05:41:12
合計ジャッジ時間 2,689 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 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 5 ms
12,052 KB
testcase_12 AC 8 ms
18,032 KB
testcase_13 AC 9 ms
18,816 KB
testcase_14 AC 7 ms
18,932 KB
testcase_15 AC 8 ms
16,752 KB
testcase_16 AC 6 ms
9,828 KB
testcase_17 AC 6 ms
12,160 KB
testcase_18 AC 7 ms
16,768 KB
testcase_19 AC 8 ms
16,128 KB
testcase_20 AC 7 ms
17,152 KB
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

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(0LL, x / 2 - 100); i <= min(x, x / 2 + 100); ++i) {
        f[i] = i - factors(i).size();
    }
    vector<pair<int, int>> ret;
    lint mini = inf;
    for (int i = max(0LL, x / 2 - 100); i <= min(x, x / 2 + 100); ++i) {
        chmin(mini, abs(f[i] - f[x - i]));
    }
    for (int i = max(0LL, x / 2 - 100); i <= min(x, x / 2 + 100); ++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