結果

問題 No.1498 Factorization from -1 to 1
ユーザー yuruhiyayuruhiya
提出日時 2021-05-06 17:36:25
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 600 bytes
コンパイル時間 22,691 ms
コンパイル使用メモリ 256,048 KB
実行使用メモリ 18,236 KB
最終ジャッジ日時 2023-10-12 09:50:26
合計ジャッジ時間 23,734 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
14,720 KB
testcase_01 AC 41 ms
14,560 KB
testcase_02 AC 41 ms
14,464 KB
testcase_03 AC 197 ms
18,236 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 40 ms
14,632 KB
testcase_16 AC 40 ms
14,720 KB
testcase_17 AC 39 ms
14,632 KB
testcase_18 AC 40 ms
14,580 KB
testcase_19 AC 40 ms
14,552 KB
testcase_20 AC 39 ms
14,464 KB
testcase_21 AC 38 ms
14,584 KB
testcase_22 AC 40 ms
14,636 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].join(' ')
end
0