結果

問題 No.1006 Share an Integer
ユーザー どららどらら
提出日時 2020-03-06 22:37:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 167,608 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-22 09:43:17
合計ジャッジ時間 4,452 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
11,224 KB
testcase_01 AC 83 ms
11,392 KB
testcase_02 AC 83 ms
11,448 KB
testcase_03 AC 82 ms
11,392 KB
testcase_04 AC 102 ms
11,392 KB
testcase_05 AC 81 ms
11,380 KB
testcase_06 AC 87 ms
11,392 KB
testcase_07 AC 83 ms
11,420 KB
testcase_08 AC 86 ms
11,264 KB
testcase_09 AC 84 ms
11,356 KB
testcase_10 AC 84 ms
11,256 KB
testcase_11 AC 88 ms
11,448 KB
testcase_12 AC 89 ms
11,392 KB
testcase_13 AC 90 ms
11,348 KB
testcase_14 AC 88 ms
11,392 KB
testcase_15 AC 87 ms
11,488 KB
testcase_16 AC 84 ms
11,264 KB
testcase_17 AC 85 ms
11,264 KB
testcase_18 AC 85 ms
11,392 KB
testcase_19 AC 87 ms
11,392 KB
testcase_20 AC 87 ms
11,520 KB
testcase_21 AC 90 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int memo[2000005];

int main(){

  REP(i,1,2000005){
    int j = i;
    while(j<2000005){
      memo[j]++;
      j+=i;
    }
  }

  int X;
  cin >> X;

  int val = 1 << 30;
  vector<pair<int,int>> v;
  
  REP(i,1,X){
    int A = i;
    int B = X - A;

    int fA = A - memo[A];
    int fB = B - memo[B];
    int diff = abs(fA-fB);

    if(val == diff){
      v.emplace_back(A,B);
    }
    else if(val > diff){
      val = diff;
      v.clear();
      v.emplace_back(A,B);
    }
  }

  rep(i,v.size()){
    cout << v[i].first << " " << v[i].second << endl;
  }
  
  return 0;
}
0