結果

問題 No.1006 Share an Integer
ユーザー pitsu_kyo_propitsu_kyo_pro
提出日時 2020-03-14 14:17:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,186 bytes
コンパイル時間 1,926 ms
コンパイル使用メモリ 178,192 KB
実行使用メモリ 813,760 KB
最終ジャッジ日時 2024-05-03 01:10:47
合計ジャッジ時間 5,271 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,576 KB
testcase_01 AC 9 ms
7,636 KB
testcase_02 AC 9 ms
7,676 KB
testcase_03 AC 9 ms
7,648 KB
testcase_04 AC 11 ms
7,564 KB
testcase_05 AC 11 ms
7,500 KB
testcase_06 AC 11 ms
7,564 KB
testcase_07 AC 11 ms
7,576 KB
testcase_08 AC 10 ms
7,532 KB
testcase_09 AC 11 ms
7,612 KB
testcase_10 AC 11 ms
7,684 KB
testcase_11 MLE -
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>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

struct Sieve{
  int n;
  vector<int> f,primes;
  Sieve(int n=1):n(n),f(n+1){
    f[0] = f[1] = -1;
    for(ll i=2; i<=n; i++){
      if(f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for(ll j=i*i; j<=n; j+=i){
        if(!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x){ return f[x] == x;}
  vector<int> factorList(int x){
    vector<int> res;
    while(x != 1){
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x){
    vector<int> fl = factorList(x);
    if(fl.size() == 0) return { };
    vector<P> res(1, P(fl[0],0));
    for(int p : fl){
      if(res.back().first == p){
        res.back().second++;
      }else{
        res.emplace_back(p,1);
      }
    }
    return res;
  }
};

Sieve sieve(1e6);
int f(int x){
  int res = 1;
  for(auto s: sieve.factor(x)){
    res *= s.second+1;
  }
  return res;
}

int main(){ 
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  int dif = inf;
  for(int i=1; i<=N-1; i++){
    int a=i,b=N-i;
    a -= f(i);
    b -= f(N-i);
    chmin(dif,abs(a-b));
  }
  vector<P> ans;
  for(int i=1; i<N; i++){
    int a=i,b=N-i;
    a -= f(i);
    b -= f(N-i);
    if(abs(a-b) == dif){
      ans.push_back(P(i,N-i));
    }
  }
  for(auto p: ans){
    cout << p.first << " " << p.second << endl;
  }
  return 0;
}
0