結果

問題 No.1498 Factorization from -1 to 1
ユーザー yuruhiyayuruhiya
提出日時 2021-05-06 17:41:03
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 605 bytes
コンパイル時間 27,677 ms
コンパイル使用メモリ 258,264 KB
実行使用メモリ 18,304 KB
最終ジャッジ日時 2023-10-12 09:55:01
合計ジャッジ時間 28,520 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
14,372 KB
testcase_01 AC 45 ms
14,500 KB
testcase_02 AC 47 ms
14,380 KB
testcase_03 AC 214 ms
17,968 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 46 ms
14,696 KB
testcase_11 AC 47 ms
14,816 KB
testcase_12 AC 47 ms
14,660 KB
testcase_13 AC 50 ms
14,692 KB
testcase_14 AC 48 ms
14,692 KB
testcase_15 AC 45 ms
14,384 KB
testcase_16 AC 44 ms
14,340 KB
testcase_17 AC 45 ms
14,360 KB
testcase_18 AC 43 ms
14,340 KB
testcase_19 AC 44 ms
14,412 KB
testcase_20 AC 43 ms
14,380 KB
testcase_21 AC 44 ms
14,388 KB
testcase_22 AC 44 ms
14,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# require "template"
lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

MAX_N = 100001i64
a = (0..MAX_N).map { |i| i.to_i64 * i + 1 }
ans = (0..MAX_N).map { [] of Int64 }

(1..MAX_N).each do |i|
  next if a[i] == 1
  prime = a[i]
  0i64.step(to: MAX_N, by: prime) do |x|
    {x - i, x + i}.each do |y|
      next unless (1..MAX_N) === y
      while a[y] % prime == 0
        ans[y] << prime
        a[y] //= prime
      end
    end
  end
end

read_line.to_i.times do
  n = read_line.to_i
  puts ans[n].sort.join(' ')
end
0