結果

問題 No.1006 Share an Integer
ユーザー beetbeet
提出日時 2020-03-06 21:52:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 671 bytes
コンパイル時間 2,371 ms
コンパイル使用メモリ 194,040 KB
実行使用メモリ 19,244 KB
最終ジャッジ日時 2024-04-22 07:16:01
合計ジャッジ時間 6,327 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
18,984 KB
testcase_01 AC 131 ms
19,200 KB
testcase_02 AC 128 ms
19,244 KB
testcase_03 AC 130 ms
19,072 KB
testcase_04 AC 137 ms
19,200 KB
testcase_05 AC 133 ms
19,072 KB
testcase_06 AC 126 ms
19,200 KB
testcase_07 AC 141 ms
19,000 KB
testcase_08 AC 148 ms
19,096 KB
testcase_09 AC 127 ms
19,100 KB
testcase_10 AC 186 ms
19,088 KB
testcase_11 AC 149 ms
19,200 KB
testcase_12 AC 130 ms
19,072 KB
testcase_13 AC 135 ms
18,940 KB
testcase_14 AC 152 ms
19,084 KB
testcase_15 AC 141 ms
19,160 KB
testcase_16 AC 132 ms
19,072 KB
testcase_17 AC 151 ms
19,200 KB
testcase_18 AC 132 ms
19,136 KB
testcase_19 AC 136 ms
19,200 KB
testcase_20 AC 137 ms
19,072 KB
testcase_21 AC 135 ms
19,072 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