結果

問題 No.1006 Share an Integer
ユーザー 995himada995himada
提出日時 2020-03-07 11:35:34
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 623 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 19,228 KB
最終ジャッジ日時 2024-04-22 12:38:46
合計ジャッジ時間 4,896 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
17,792 KB
testcase_01 AC 88 ms
12,160 KB
testcase_02 AC 87 ms
12,160 KB
testcase_03 WA -
testcase_04 AC 92 ms
12,160 KB
testcase_05 AC 88 ms
12,160 KB
testcase_06 AC 90 ms
12,288 KB
testcase_07 AC 89 ms
12,288 KB
testcase_08 AC 89 ms
12,160 KB
testcase_09 AC 90 ms
12,288 KB
testcase_10 AC 89 ms
12,288 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

include Math
INF = 10 ** 12
def div_size(n)
  res = 0
  i = 1
  while i * i <= n
    if n % i == 0
      if n / i != i
        res += 2
      else
        res += 1
      end
    end
    i += 1
  end
  return res
end
X = gets.to_i

a = X / 2
b = (X + 1) / 2
pre = INF
ans = []

# binding.pry

while a > sqrt(X).floor && b <= X
  avalue = a - div_size(a)
  bvalue = b - div_size(b)
  dist = (avalue - bvalue).abs
  if pre > dist
    (ans = []) << [a, b] << [b, a]
    pre = dist
  elsif pre == dist
    ans << [a, b] << [b, a]
  end
  a -= 1
  b += 1
end
ans.uniq.sort_by!{|x, y|x}.each do |an|
  puts "#{an[0]} #{an[1]}"
end
0