結果

問題 No.1006 Share an Integer
ユーザー yomo3yomo3
提出日時 2020-04-07 00:12:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,172 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 169,956 KB
実行使用メモリ 14,908 KB
最終ジャッジ日時 2023-09-21 12:06:18
合計ジャッジ時間 3,320 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 34 ms
9,508 KB
testcase_12 AC 73 ms
14,176 KB
testcase_13 AC 79 ms
14,908 KB
testcase_14 AC 79 ms
14,720 KB
testcase_15 AC 65 ms
13,252 KB
testcase_16 AC 25 ms
7,992 KB
testcase_17 AC 35 ms
9,700 KB
testcase_18 AC 64 ms
13,180 KB
testcase_19 AC 58 ms
12,672 KB
testcase_20 AC 68 ms
13,352 KB
testcase_21 AC 79 ms
14,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}

int main()
{
    int X; cin >> X;

    vector<int> divs(X+1, 1);
    divs[0] = 0;
    for (int i = 2; i <= X; i++) {
        divs[i]++;
        for (int j = i+i; j <= X; j += i) {
            divs[j]++;
        }
    }

    int least = INT_MAX;

    vector<int> diff(X/2 + 1);
    for (int a = 1; a < diff.size(); a++) {
        int b = X - a;
        diff[a] = abs(a - divs[a] - (b - divs[b]));
        chmin(least, diff[a]);
    }

    vector<pair<int,int>> rev;
    for (int a = 1; a < diff.size(); a++) {
        if (diff[a] == least) {
            int b = X - a;
            cout << a << " " << b << endl;
            if (a != b)
                rev.push_back(make_pair(b, a));
        }
    }
    for (auto it = rev.rbegin(); it != rev.rend(); it++) {
        cout << (*it).first << " " << (*it).second << endl;

    }
}
0