結果

問題 No.1006 Share an Integer
ユーザー totori_nyaatotori_nyaa
提出日時 2020-03-06 22:13:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 894 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 173,028 KB
実行使用メモリ 126,232 KB
最終ジャッジ日時 2024-04-22 08:11:54
合計ジャッジ時間 4,391 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 110 ms
71,876 KB
testcase_12 AC 195 ms
119,420 KB
testcase_13 AC 202 ms
126,172 KB
testcase_14 AC 204 ms
126,232 KB
testcase_15 AC 177 ms
108,492 KB
testcase_16 AC 81 ms
55,104 KB
testcase_17 AC 111 ms
73,692 KB
testcase_18 AC 180 ms
109,216 KB
testcase_19 AC 163 ms
104,744 KB
testcase_20 AC 178 ms
112,616 KB
testcase_21 AC 197 ms
126,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    if(n==2){
        cout << 1 << " " << 1<< endl;
        return 0;
    }
    vector<int> v(n+1,1);
    vector<vector<int>> ans(2*n+1);
    for(int i=2;i<=n;i++){
        for(int j=i;j<=n;j+=i){
            v[j]++;
        }
        v[i] = i-v[i];
        if(i > n-i){
            ans[abs(v[i]-v[n-i])].push_back(i);
            ans[abs(v[i]-v[n-i])].push_back(n-i);
        }
        if(i==n-i){
            ans[abs(v[i]-v[n-i])].push_back(i);
        }
    }
    for(int i=0;i<=n;i++){
        if(ans[i].size()){
            sort(ans[i].begin(),ans[i].end());
            for(auto j:ans[i]){
                cout << j << " " << n-j << "\n";
            }
            return 0;
        }
    }
}
0