結果
| 問題 | No.546 オンリー・ワン | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-07-14 23:07:44 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 93 ms / 2,000 ms | 
| コード長 | 542 bytes | 
| コンパイル時間 | 77 ms | 
| コンパイル使用メモリ | 7,424 KB | 
| 実行使用メモリ | 12,288 KB | 
| 最終ジャッジ日時 | 2024-10-07 23:29:35 | 
| 合計ジャッジ時間 | 1,837 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
コンパイルメッセージ
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
ソースコード
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
            
            
            
        