結果

問題 No.368 LCM of K-products
ユーザー maimai
提出日時 2018-02-02 00:51:05
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 594 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 11,396 KB
実行使用メモリ 20,204 KB
最終ジャッジ日時 2023-08-28 18:05:54
合計ジャッジ時間 5,904 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 347 ms
20,036 KB
testcase_01 AC 1,003 ms
15,700 KB
testcase_02 AC 94 ms
15,316 KB
testcase_03 AC 363 ms
15,380 KB
testcase_04 AC 157 ms
15,380 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

def mypow(x,w,md)
    y=1
    while 0<w
        y = (x*y)%md if w.odd?
        w/=2
        x = (x*x)%md
    end
    y
end

require 'prime'

MD = 1000000007

N,K = ascan
aa = ascan.sort

# p aa.combination(K).map{|z| z.reduce(:*)}.reduce(:lcm)%MD

primes = aa.reduce({}) do |s,a|
    Prime.prime_division(a).each do |k,v|
        s[k] ||= []
        s[k] << v
    end
    s
end

ans = 1

primes.each do |k, v|
    ans *= mypow(k,(v.sort.pop([K,v.size].min).reduce(:+)),MD)
    ans %= MD
    STDERR.puts "#{[k,v,ans]}"
end

p ans

# case
# 3 2
# 100 11 10
0