結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー LeonardoneLeonardone
提出日時 2015-12-09 06:47:04
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,906 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 11,288 KB
実行使用メモリ 15,376 KB
最終ジャッジ日時 2023-10-12 22:44:09
合計ジャッジ時間 4,830 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,152 KB
testcase_01 WA -
testcase_02 AC 80 ms
15,024 KB
testcase_03 AC 80 ms
15,268 KB
testcase_04 AC 80 ms
15,188 KB
testcase_05 RE -
testcase_06 AC 80 ms
15,276 KB
testcase_07 RE -
testcase_08 AC 81 ms
15,204 KB
testcase_09 AC 80 ms
15,316 KB
testcase_10 AC 80 ms
15,128 KB
testcase_11 RE -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 80 ms
15,136 KB
testcase_15 AC 79 ms
15,196 KB
testcase_16 AC 80 ms
15,216 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 81 ms
15,192 KB
testcase_24 AC 80 ms
15,052 KB
testcase_25 WA -
testcase_26 AC 78 ms
15,104 KB
testcase_27 AC 79 ms
15,168 KB
testcase_28 AC 78 ms
15,268 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 78 ms
15,312 KB
testcase_32 WA -
testcase_33 RE -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#! ruby
# yukicoder My Practice
# author: Leonardone @ NEETSDKASU

def gi(); gets.to_i; end
def gis(); gets.chomp.split.map(&:to_i); end

=begin

1~Nまでの間には
aの倍数が n/a 個 
bの倍数が n/b 個
cの倍数が n/c 個

a*bの倍数が n/(a*b)個
b*cの倍数が n/(b*c)個
c*aの倍数が n/(c*a)個

a*b*cの倍数が n/(a*b*c)個

和集合とかいうやつで集合の足し算引き算で求める感じ?

    1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 2     *     *     *     *     *     *     *           *     *     *     *     *     *     *
 3        *        *        *        *        *        *        *        *        *        *
 5              *              *              *              *              *              *
 6                 @                 @                 @                 @                 @
10                             @                             @                             @
15                                            @                                            @
30                                                                                         #

=end

n = gi
a, b, c = gis

a_cnt = n.div a
b_cnt = n.div b
c_cnt = n.div c
ab_cnt = n.div (a * b)
bc_cnt = n.div (b * c)
ca_cnt = n.div (c * a)
abc_cnt = n.div (a * b * c)

answer = case 
    when b % a == 0 && c % a == 0
        a_cnt
    when c % b == 0 || c % a == 0
        a_cnt + b_cnt - ab_cnt
    when b % a == 0
        a_cnt + c_cnt - cb_cnt
    else
        a_cnt + b_cnt + c_cnt - (ab_cnt + bc_cnt + ca_cnt) + abc_cnt
    end

p answer

$stdout = STDERR

p n
p [a, b, c, a * b, b * c, c * a, a * b * c]
p [a_cnt, b_cnt, c_cnt, ab_cnt, bc_cnt, ca_cnt, abc_cnt]


# 素直に解く

=begin 

    cnt = 0
    
    1.upto(n) do |i|
        cnt += 1 if i % a == 0 || i % b == 0 || i % c == 0
    end
    
    p cnt

=end
0