結果

問題 No.1006 Share an Integer
ユーザー DenteDente
提出日時 2020-03-06 22:16:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 399 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 172,276 KB
実行使用メモリ 45,608 KB
最終ジャッジ日時 2024-04-22 08:23:38
合計ジャッジ時間 6,180 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 218 ms
38,536 KB
testcase_12 AC 379 ms
42,752 KB
testcase_13 AC 399 ms
45,608 KB
testcase_14 AC 399 ms
44,316 KB
testcase_15 AC 346 ms
43,064 KB
testcase_16 AC 157 ms
22,632 KB
testcase_17 AC 225 ms
38,168 KB
testcase_18 AC 337 ms
41,632 KB
testcase_19 AC 329 ms
41,552 KB
testcase_20 AC 353 ms
42,524 KB
testcase_21 AC 391 ms
44,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

vector<int> eratos(int n){
    vector<int> res(n + 1, 2);
    for (int i = 2; i <= n; i++) {
        for (int j = 2 * i; j <= n; j += i) {
            res[j]++;
        }
    }
    return res;
}

signed main(){
    ll x;
    cin >> x;
    auto e = eratos(x);
    vector<int> f(x + 1);
    for (int i = 1; i <= x; i++){
        f[i] = i - e[i];
    }
    vector<pair<int, P>> v;
    for (int i = 1; i < x; i++) {
        v.emplace_back(pair<int, P>(abs(f[i] - f[x - i]), {i, x - i}));
    }
    sort(ALL(v));
    int i = 0;
    while (i < v.size() && v[i].first == v[0].first){
        cout << v[i].second.first << " " << v[i].second.second << endl;
        i++;
    }
    return 0;
}
0