結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー LeonardoneLeonardone
提出日時 2015-12-09 07:33:48
言語 Ruby
(3.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,429 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 11,312 KB
実行使用メモリ 15,392 KB
最終ジャッジ日時 2023-08-10 20:26:53
合計ジャッジ時間 4,570 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,316 KB
testcase_01 AC 79 ms
15,052 KB
testcase_02 AC 78 ms
15,124 KB
testcase_03 AC 79 ms
15,272 KB
testcase_04 AC 78 ms
15,168 KB
testcase_05 AC 78 ms
15,052 KB
testcase_06 AC 76 ms
15,176 KB
testcase_07 AC 77 ms
15,348 KB
testcase_08 AC 76 ms
15,244 KB
testcase_09 AC 75 ms
15,248 KB
testcase_10 AC 76 ms
15,160 KB
testcase_11 AC 75 ms
15,128 KB
testcase_12 AC 76 ms
15,052 KB
testcase_13 AC 78 ms
15,164 KB
testcase_14 AC 77 ms
15,236 KB
testcase_15 AC 78 ms
15,052 KB
testcase_16 AC 78 ms
15,156 KB
testcase_17 AC 76 ms
15,040 KB
testcase_18 AC 78 ms
15,160 KB
testcase_19 AC 78 ms
15,240 KB
testcase_20 AC 77 ms
15,112 KB
testcase_21 AC 76 ms
15,312 KB
testcase_22 AC 76 ms
15,116 KB
testcase_23 AC 76 ms
15,028 KB
testcase_24 AC 78 ms
15,108 KB
testcase_25 AC 77 ms
15,160 KB
testcase_26 AC 77 ms
15,164 KB
testcase_27 AC 76 ms
15,128 KB
testcase_28 AC 78 ms
15,168 KB
testcase_29 AC 79 ms
15,276 KB
testcase_30 AC 75 ms
15,236 KB
testcase_31 AC 78 ms
15,060 KB
testcase_32 AC 78 ms
15,320 KB
testcase_33 WA -
testcase_34 AC 77 ms
15,164 KB
testcase_35 AC 77 ms
15,244 KB
testcase_36 AC 78 ms
15,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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                                                                                         #

最小公倍数なケースがあるんよ
         30  42  60  70  84  90 120 126 140 210 280
a =   6   *   *   *       *   *   *   *
b =  10   *       *   *       *   *       *   *   *
c =  14       *       *   *           *   *   *   *
ab=  60           @               @
bc= 140                                   @       @
ca   84                   @



=end

n = gi
a, b, c = gis.sort

if a == 1
    puts n
    exit
end

if n < a
    puts '0'
    exit
end

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

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

puts answer

=begin
$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]
p a_cnt + b_cnt + c_cnt
=end


# 素直に解く

=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