結果

問題 No.1006 Share an Integer
ユーザー beetbeet
提出日時 2020-03-06 21:52:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 671 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 198,576 KB
実行使用メモリ 19,240 KB
最終ジャッジ日時 2023-08-04 09:30:32
合計ジャッジ時間 6,216 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
19,028 KB
testcase_01 AC 130 ms
18,988 KB
testcase_02 AC 130 ms
18,992 KB
testcase_03 AC 129 ms
18,928 KB
testcase_04 AC 133 ms
19,000 KB
testcase_05 AC 145 ms
18,940 KB
testcase_06 AC 152 ms
18,984 KB
testcase_07 AC 146 ms
19,132 KB
testcase_08 AC 142 ms
19,040 KB
testcase_09 AC 143 ms
18,944 KB
testcase_10 AC 137 ms
19,216 KB
testcase_11 AC 141 ms
18,988 KB
testcase_12 AC 142 ms
19,040 KB
testcase_13 AC 147 ms
19,044 KB
testcase_14 AC 149 ms
19,136 KB
testcase_15 AC 136 ms
18,996 KB
testcase_16 AC 122 ms
18,928 KB
testcase_17 AC 134 ms
19,204 KB
testcase_18 AC 135 ms
18,984 KB
testcase_19 AC 132 ms
19,240 KB
testcase_20 AC 147 ms
19,056 KB
testcase_21 AC 157 ms
18,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 2e6+100;
Int cnt[MAX]={};
Int calc(Int a,Int b){
  return abs((a-cnt[a])-(b-cnt[b]));
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  for(Int i=1;i<MAX;i++)
    for(Int j=i;j<MAX;j+=i)
      cnt[j]++;

  Int x;
  cin>>x;
  Int res=MAX;
  for(Int a=1;a<x;a++)
    chmin(res,calc(a,x-a));

  for(Int a=1;a<x;a++)
    if(calc(a,x-a)==res)
      cout<<a<<" "<<x-a<<"\n";
  cout<<flush;
  return 0;
}
0