結果

問題 No.1498 Factorization from -1 to 1
ユーザー yuruhiyayuruhiya
提出日時 2021-05-06 17:47:54
言語 Crystal
(1.11.2)
結果
AC  
実行時間 258 ms / 3,000 ms
コード長 613 bytes
コンパイル時間 17,632 ms
コンパイル使用メモリ 258,388 KB
実行使用メモリ 18,068 KB
最終ジャッジ日時 2023-10-12 10:01:56
合計ジャッジ時間 21,792 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
14,412 KB
testcase_01 AC 41 ms
14,528 KB
testcase_02 AC 42 ms
14,424 KB
testcase_03 AC 208 ms
17,980 KB
testcase_04 AC 229 ms
17,984 KB
testcase_05 AC 248 ms
17,908 KB
testcase_06 AC 258 ms
18,068 KB
testcase_07 AC 251 ms
17,884 KB
testcase_08 AC 253 ms
17,916 KB
testcase_09 AC 253 ms
18,068 KB
testcase_10 AC 45 ms
14,684 KB
testcase_11 AC 45 ms
14,744 KB
testcase_12 AC 44 ms
14,776 KB
testcase_13 AC 46 ms
14,788 KB
testcase_14 AC 45 ms
14,672 KB
testcase_15 AC 42 ms
14,484 KB
testcase_16 AC 41 ms
14,420 KB
testcase_17 AC 43 ms
14,428 KB
testcase_18 AC 42 ms
14,316 KB
testcase_19 AC 44 ms
14,568 KB
testcase_20 AC 42 ms
14,364 KB
testcase_21 AC 41 ms
14,344 KB
testcase_22 AC 42 ms
14,356 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 + prime, 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