結果

問題 No.546 オンリー・ワン
ユーザー maimai
提出日時 2017-07-14 23:07:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 542 bytes
コンパイル時間 54 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-16 20:31:12
合計ジャッジ時間 1,684 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
12,160 KB
testcase_01 AC 92 ms
12,288 KB
testcase_02 AC 91 ms
12,160 KB
testcase_03 AC 91 ms
12,160 KB
testcase_04 AC 93 ms
12,160 KB
testcase_05 AC 95 ms
12,288 KB
testcase_06 AC 96 ms
12,160 KB
testcase_07 AC 99 ms
12,288 KB
testcase_08 AC 98 ms
12,160 KB
testcase_09 AC 98 ms
12,288 KB
testcase_10 AC 104 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:26: warning: `-' after local variable or literal is interpreted as binary operator
Main.rb:26: warning: even though it seems like unary operator
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_i); end
def scan; gets.to_i; end

def gcd(a,b)
    0<b ? gcd(b, a % b) : a
end
def lcm(a,b)
    a * b / gcd(a, b)
end

n,l,h = ascan
cc = ascan
l-=1

r = 0
#cc.each{|c|
#    flg = false
#    cc.each{|d|
#        flg |= c%d==0 if c!=d
#    }
#    unless flg
#        r += h/c -l/ c
#    end
#}
cc.each{|c|
    r += h/c -l/ c
}
#p r
2.upto(n){|i|
    cc.combination(i){|v|
        e = v.inject(1){|s,x| lcm(s,x)}
        
        tmp = h/e - l/ e
        #p [v,e,tmp]
        r +=tmp*(i.odd?? i : -i)
    }
}

p r
0