結果

問題 No.1006 Share an Integer
ユーザー sugarrrsugarrr
提出日時 2020-03-06 21:37:28
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 703 ms / 2,000 ms
コード長 2,340 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 135,476 KB
実行使用メモリ 34,788 KB
最終ジャッジ日時 2023-08-20 14:09:03
合計ジャッジ時間 9,184 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 355 ms
21,588 KB
testcase_12 AC 661 ms
33,060 KB
testcase_13 AC 703 ms
34,768 KB
testcase_14 AC 701 ms
34,788 KB
testcase_15 AC 577 ms
30,804 KB
testcase_16 AC 254 ms
17,216 KB
testcase_17 AC 361 ms
21,944 KB
testcase_18 AC 590 ms
31,564 KB
testcase_19 AC 553 ms
30,620 KB
testcase_20 AC 614 ms
31,284 KB
testcase_21 AC 698 ms
34,672 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