結果

問題 No.278 連続する整数の和(2)
ユーザー simansiman
提出日時 2022-04-02 15:04:26
言語 Ruby
(3.3.0)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 420 bytes
コンパイル時間 60 ms
コンパイル使用メモリ 11,240 KB
実行使用メモリ 15,548 KB
最終ジャッジ日時 2023-08-13 18:19:55
合計ジャッジ時間 3,021 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
15,340 KB
testcase_01 AC 75 ms
15,084 KB
testcase_02 AC 172 ms
15,548 KB
testcase_03 AC 74 ms
15,408 KB
testcase_04 AC 74 ms
15,372 KB
testcase_05 AC 74 ms
15,332 KB
testcase_06 AC 75 ms
15,368 KB
testcase_07 AC 74 ms
15,284 KB
testcase_08 AC 74 ms
15,340 KB
testcase_09 AC 76 ms
15,300 KB
testcase_10 AC 75 ms
15,280 KB
testcase_11 AC 85 ms
15,352 KB
testcase_12 AC 75 ms
15,412 KB
testcase_13 AC 137 ms
15,544 KB
testcase_14 AC 81 ms
15,436 KB
testcase_15 AC 109 ms
15,296 KB
testcase_16 AC 85 ms
15,392 KB
testcase_17 AC 82 ms
15,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Integer
  def divisor_list
    require 'prime'

    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..k).map { |n| base ** n }
    }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort
  end
end

N = gets.to_i
a = (N - 1) * N / 2
ans = 0

N.divisor_list.each do |e|
  ans += e if a % e == 0
end

puts ans
0