結果

問題 No.1006 Share an Integer
ユーザー sugarrrsugarrr
提出日時 2020-03-06 21:37:28
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 731 ms / 2,000 ms
コード長 2,340 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 165,088 KB
実行使用メモリ 34,808 KB
最終ジャッジ日時 2024-05-07 20:37:32
合計ジャッジ時間 9,252 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 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 2 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 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 365 ms
20,864 KB
testcase_12 AC 677 ms
33,024 KB
testcase_13 AC 729 ms
34,808 KB
testcase_14 AC 731 ms
34,640 KB
testcase_15 AC 605 ms
30,336 KB
testcase_16 AC 261 ms
16,768 KB
testcase_17 AC 372 ms
21,376 KB
testcase_18 AC 617 ms
30,464 KB
testcase_19 AC 577 ms
29,184 KB
testcase_20 AC 630 ms
31,360 KB
testcase_21 AC 720 ms
34,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
///////////////////////////

#define N 2000002
ll f[N];
#define MAX_N (ll)2E4///変更!!!!!!!
vector<ll>prime;
bool is_prime[MAX_N+1];
void precal(){
    rep(i,0,MAX_N)is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    rep(i,2,MAX_N){
        if(is_prime[i]){
            prime.pb(i);
            for(ll j=2*i;j<=MAX_N;j+=i)is_prime[j]=false;
        }
    }
}
ll fact(ll n){
    vector<l_l>v;
    for(ll p:prime){
        if(p*p>n)break;
        ll c=0;
        while(n%p==0){
            n/=p;
            c++;
        }
        if(c)v.pb(l_l(p,c));//pという素因数がc個入っている
    }
    if(n!=1){
        ll vsize=v.size();
        if(vsize>=1&&v[vsize-1].first==n)v[vsize-1].second++;
        else v.pb(l_l(n,1));
    }
    /*
    if(v.size()==0){
        v.pb(l_l(1,1));
    }*/
    //return v;
    ll res=1;
    for(auto x:v){
        res*=x.second+1;
    }
    return res;
}
/////////////////////////////////////////////////////
ll x;
void calc(){
    precal();
    f[1]=0;
    rep(i,2,x){
        f[i]=i-fact(i);
    }
}

int main(){fastio
    
    cin>>x;
    calc();
    ll dis[x];
    ll mini=inf;
    rep(i,1,x-1){
        ll a=i,b=x-i;
        dis[i]=abs(f[a]-f[b]);
        Min(mini,dis[i]);
    }
    //rep(i,1,10)cout<<f[i]<<" ";cout<<endl;/
    //rep(i,1,10)cout<<dis[i]<<" ";cout<<endl;
    vector<ll>ans;
    rep(i,1,x-1){
        if(mini==dis[i])ans.pb(i);
    }
    for(auto y:ans){
        cout<<y<<" "<<x-y<<endl;
    }
    return 0;
}
0