結果

問題 No.1006 Share an Integer
ユーザー kappybarkappybar
提出日時 2020-03-24 16:30:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,610 bytes
コンパイル時間 1,864 ms
コンパイル使用メモリ 173,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 05:34:57
合計ジャッジ時間 3,466 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int d(int i){
        int cnt = 1;
        int p = i;
        for(int j=2; j*j<=i;j++){
                if(p%j == 0){
                        int q = 0;
                        while(p%j == 0){
                                q ++;
                                p /= j;
                        }
                        cnt *= q + 1;
                }
        }
        if(p > 1) cnt *= 2;
        return cnt;
}


 
int main() {
        //clock_t start = clock();

        int x;
        cin >> x;

        int m = INF;
        int a = x/2;
        vector<pair<int,int>> ans;
        rep(i,min(300,x/2)){
                int f = abs(a-d(a) - (x-a - d(x-a)));
                if(f < m){
                        if(a == x-a){
                                ans = {pp(a,x-a)};
                                m = f;
                        }
                        else{
                                ans = {pp(a,x-a),pp(x-a,a)};
                                m = f;
                        }
                }
                else if(f == m){
                        ans.push_back(pp(a,x-a));
                        ans.push_back(pp(x-a,a));
                }
                -- a;
        }

        sort(ans.begin(),ans.end());

        for(auto a:ans) cout << a.first << " " << a.second << endl;

        //clock_t end = clock();

        //printf("%.7f",(double)(end - start)/CLOCKS_PER_SEC);

        return 0;
}



0