結果

問題 No.1747 Many Formulae 2
ユーザー maguroflymagurofly
提出日時 2021-11-19 21:24:01
言語 Ruby
(3.3.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 271 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 11,556 KB
実行使用メモリ 15,600 KB
最終ジャッジ日時 2023-08-30 07:13:20
合計ジャッジ時間 3,117 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
15,392 KB
testcase_01 AC 92 ms
15,392 KB
testcase_02 AC 93 ms
15,440 KB
testcase_03 AC 97 ms
15,356 KB
testcase_04 AC 94 ms
15,388 KB
testcase_05 AC 94 ms
15,600 KB
testcase_06 AC 95 ms
15,388 KB
testcase_07 AC 95 ms
15,528 KB
testcase_08 AC 95 ms
15,308 KB
testcase_09 AC 94 ms
15,396 KB
testcase_10 AC 93 ms
15,436 KB
testcase_11 AC 94 ms
15,560 KB
testcase_12 AC 95 ms
15,516 KB
testcase_13 AC 94 ms
15,420 KB
testcase_14 AC 98 ms
15,304 KB
testcase_15 AC 99 ms
15,400 KB
testcase_16 AC 98 ms
15,384 KB
testcase_17 AC 96 ms
15,300 KB
testcase_18 AC 96 ms
15,440 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require "prime"
require "set"
S = gets.chomp.chars.map(&:to_i)
N = S.size
ans = 0
(1 << N - 1).times do |bits|
    a = [S[0]]
    (1 ... N).each do |i|
        a << 0 if bits[i - 1] == 1
        a[-1] = a[-1] * 10 + S[i]
    end
    ans += 1 if a.sum.prime?
end

puts ans
0