結果

問題 No.1006 Share an Integer
ユーザー betrue12betrue12
提出日時 2020-03-06 21:38:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 2,780 ms
コンパイル使用メモリ 203,016 KB
実行使用メモリ 11,324 KB
最終ジャッジ日時 2024-04-22 05:26:36
合計ジャッジ時間 3,864 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 36 ms
7,808 KB
testcase_12 AC 65 ms
10,752 KB
testcase_13 AC 75 ms
11,136 KB
testcase_14 AC 72 ms
11,008 KB
testcase_15 AC 59 ms
10,072 KB
testcase_16 AC 26 ms
6,912 KB
testcase_17 AC 37 ms
7,940 KB
testcase_18 AC 60 ms
10,120 KB
testcase_19 AC 56 ms
9,976 KB
testcase_20 AC 62 ms
10,476 KB
testcase_21 AC 75 ms
11,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int X;
    cin >> X;
    vector<int> num(X+1);
    for(int i=1; i<=X; i++) for(int j=i; j<=X; j+=i) num[j]++;

    int opt = 1e9;
    vector<pair<int, int>> ans;
    for(int i=1; i<=X-i; i++){
        int j = X-i;
        int d = abs((i-num[i]) - (j-num[j]));
        if(opt > d){
            ans.clear();
            opt = d;
        }
        if(opt == d){
            ans.emplace_back(i, j);
            if(i < j) ans.emplace_back(j, i);
        }
    }
    sort(ans.begin(), ans.end());
    for(auto& p : ans) printf("%d %d\n", p.first, p.second);
    return 0;
}
0