結果

問題 No.1006 Share an Integer
ユーザー tanimani364tanimani364
提出日時 2020-03-06 22:19:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 2,030 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 154,588 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 08:39:02
合計ジャッジ時間 3,425 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 49 ms
5,376 KB
testcase_12 AC 58 ms
5,376 KB
testcase_13 AC 60 ms
5,376 KB
testcase_14 AC 60 ms
5,376 KB
testcase_15 AC 56 ms
5,376 KB
testcase_16 AC 44 ms
5,376 KB
testcase_17 AC 49 ms
5,376 KB
testcase_18 AC 56 ms
5,376 KB
testcase_19 AC 55 ms
5,376 KB
testcase_20 AC 57 ms
5,376 KB
testcase_21 AC 60 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

#define int64_t ll
map< int64_t, ll > prime_factor(int64_t n) {
  map< int64_t, ll > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


using P=pair<ll,ll>;
void solve(){
  ll x;
  cin>>x;
  set<P>st;
  map<ll,ll>mp;
  ll ans=INF;
  rep(i,10000){
    ll a=x/2-i;
    ll b=x-a;
    if(a<=0||b<=0)continue;
    ll sum_a=1,sum_b=1;
    mp=prime_factor(a);
    for(auto e:mp){
      sum_a*=e.second+1;
    }
    ll aa=a-sum_a;
    mp=prime_factor(b);
    for(auto e:mp){
      sum_b*=e.second+1;
    }
    ll bb=b-sum_b;
    if(chmin(ans,abs(aa-bb))){
      st.clear();
      st.emplace(a,b);
      st.emplace(b,a);
    }
    else if(ans==abs(aa-bb)){
      st.emplace(a,b);
      st.emplace(b,a);
    }
  }
  for(auto e:st){
    cout<<e.first<<" "<<e.second<<endl;
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}
0