結果

問題 No.1006 Share an Integer
ユーザー kibunakibuna
提出日時 2020-03-06 21:39:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,111 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 172,636 KB
実行使用メモリ 18,872 KB
最終ジャッジ日時 2024-04-22 05:29:24
合計ジャッジ時間 5,409 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
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 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 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;
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 = 0; i <= x; ++i) {
        f[i] = i - factors(i).size();
    }
    vector<pair<int, int>> ret;
    lint mini = inf;
    for (int i = 1; i < x; ++i) {
        chmin(mini, abs(f[i] - f[x - i]));
    }
    for (int i = 1; i < x; ++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