結果

問題 No.1006 Share an Integer
ユーザー totori_nyaatotori_nyaa
提出日時 2020-03-06 21:51:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,064 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 166,012 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-22 07:12:24
合計ジャッジ時間 5,496 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
    int x[n+1]={};
    vector<int> p;
    bool prime[n+1]={};
    for(int i=2;i*i<=n;i++){
        if(prime[i]==0){
            for(int j=i+i;j<=n;j+=i){
                prime[j] = 1;
            }
        }
    }
    prime[0]=prime[1]=1;
    for(int i=0;i<=n;i++){
        if(prime[i]==0){
            p.push_back(i);
        }
    }
    for(int val=1;val<=n;val++){
        int ret = 1;
        int t = val;
        for(auto i:p){
            int cnt = 0;
            while(t%i==0){
                t/=i;
                cnt++;
            }
            ret *= (cnt+1);
            if(t==1)break;
        }
        x[val] = val-ret;
    }
    int ans = 11111110;
    for(int i=1;i<n;i++){
        ans = min(ans,abs(x[i]-x[n-i]));
    }
    for(int i=1;i<n;i++){
        if(abs(x[i]-x[n-i]) == ans){
            cout << i << " " << n-i << "\n";
        }
    }
    
}
0