結果

問題 No.1946 ロッカーの問題
ユーザー tomeruntomerun
提出日時 2022-05-20 21:44:10
言語 Crystal
(1.11.2)
結果
AC  
実行時間 305 ms / 3,000 ms
コード長 383 bytes
コンパイル時間 17,148 ms
コンパイル使用メモリ 293,008 KB
実行使用メモリ 16,028 KB
最終ジャッジ日時 2023-10-20 12:11:55
合計ジャッジ時間 19,234 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 248 ms
16,028 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 7 ms
4,348 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 56 ms
7,436 KB
testcase_09 AC 213 ms
15,968 KB
testcase_10 AC 170 ms
12,432 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 33 ms
4,700 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 116 ms
7,356 KB
testcase_18 AC 305 ms
12,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = read_line.split.map(&.to_i)
a = read_line.split.map(&.to_i)
open = Array.new(n + 1, 0)
a.each do |i|
  open[i] = 1
end
ans = 0
n.downto(1) do |i|
  if open[i] == 0
    ans += 1
  else
    d = 1
    while d * d < i
      if i % d == 0
        open[i // d] ^= 1
        open[d] ^= 1
      end
      d += 1
    end
    if d * d == i
      open[d] ^= 1
    end
  end
end
puts ans
0