結果

問題 No.1006 Share an Integer
ユーザー 995himada995himada
提出日時 2020-03-07 11:44:48
言語 Ruby
(3.3.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 636 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-22 12:39:29
合計ジャッジ時間 4,416 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
12,160 KB
testcase_01 AC 83 ms
12,032 KB
testcase_02 AC 81 ms
12,160 KB
testcase_03 AC 82 ms
12,160 KB
testcase_04 AC 78 ms
12,032 KB
testcase_05 AC 79 ms
12,160 KB
testcase_06 AC 79 ms
12,160 KB
testcase_07 AC 81 ms
12,160 KB
testcase_08 AC 81 ms
12,288 KB
testcase_09 AC 81 ms
12,160 KB
testcase_10 AC 80 ms
12,160 KB
testcase_11 AC 157 ms
12,288 KB
testcase_12 AC 215 ms
12,160 KB
testcase_13 AC 215 ms
12,160 KB
testcase_14 AC 220 ms
12,160 KB
testcase_15 AC 195 ms
12,032 KB
testcase_16 AC 138 ms
12,160 KB
testcase_17 AC 157 ms
12,288 KB
testcase_18 AC 193 ms
12,160 KB
testcase_19 AC 197 ms
12,160 KB
testcase_20 AC 201 ms
12,032 KB
testcase_21 AC 216 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 > 0 && b <= (X + 1) / 2 + sqrt(X).ceil
  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