結果

問題 No.1006 Share an Integer
ユーザー pitsu_kyo_propitsu_kyo_pro
提出日時 2020-03-14 14:21:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,270 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 178,580 KB
実行使用メモリ 11,492 KB
最終ジャッジ日時 2024-05-03 01:11:24
合計ジャッジ時間 5,941 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
11,384 KB
testcase_01 AC 13 ms
11,352 KB
testcase_02 AC 14 ms
11,396 KB
testcase_03 AC 14 ms
11,276 KB
testcase_04 AC 13 ms
11,436 KB
testcase_05 AC 13 ms
11,408 KB
testcase_06 AC 14 ms
11,492 KB
testcase_07 AC 14 ms
11,276 KB
testcase_08 AC 13 ms
11,400 KB
testcase_09 AC 13 ms
11,404 KB
testcase_10 AC 13 ms
11,404 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 185 ms
11,452 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

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;
  vector<int> vec(1e6);
  for(int i=1; i<=N-1; i++){
    vec[i] = f(i);
  }
  for(int i=1; i<=N-1; i++){
    int a=i,b=N-i;
    a -= vec[i];
    b -= vec[N-i];
    chmin(dif,abs(a-b));
  }
  vector<P> ans;
  for(int i=1; i<N; i++){
    int a=i,b=N-i;
    a -= vec[i];
    b -= vec[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