結果

問題 No.1006 Share an Integer
ユーザー simansiman
提出日時 2020-09-11 06:16:04
言語 Ruby
(3.2.2)
結果
TLE  
実行時間 -
コード長 708 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 11,480 KB
実行使用メモリ 31,108 KB
最終ジャッジ日時 2023-08-26 02:24:00
合計ジャッジ時間 24,817 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
15,128 KB
testcase_01 AC 73 ms
15,356 KB
testcase_02 AC 75 ms
15,052 KB
testcase_03 AC 70 ms
15,120 KB
testcase_04 AC 74 ms
15,256 KB
testcase_05 AC 73 ms
15,284 KB
testcase_06 AC 69 ms
15,260 KB
testcase_07 AC 69 ms
15,160 KB
testcase_08 AC 71 ms
15,240 KB
testcase_09 AC 73 ms
15,304 KB
testcase_10 AC 72 ms
15,320 KB
testcase_11 AC 1,404 ms
23,996 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 1,077 ms
21,868 KB
testcase_17 AC 1,422 ms
24,160 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

X = gets.to_i

SPF = Array.new(X + 1, -1)
SPF[0] = 0
SPF[1] = 1

2.upto(X) do |x|
  next if SPF[x] != -1

  x.step(X, x) do |n|
    next if SPF[n] != -1

    SPF[n] = x
  end
end

def divisor_count(x)
  res = 1
  cur = -1
  cnt = 0

  while x != 1
    f = SPF[x]

    if cur != f
      res *= (cnt + 1)
      cur = f
      cnt = 1
    else
      cnt += 1
    end

    x /= f
  end

  res * (cnt + 1)
end

min_diff = Float::INFINITY
ans = []

1.upto(X - 1) do |a|
  b = X - a
  v1 = a - divisor_count(a)
  v2 = b - divisor_count(b)
  diff = (v1 - v2).abs

  if min_diff > diff
    min_diff = diff
    ans = [[a, b]]
  elsif min_diff == diff
    ans << [a, b]
  end
end

puts ans.map { |nums| nums.join(' ') }
0