結果

問題 No.377 背景パターン
ユーザー cielciel
提出日時 2021-06-15 00:16:15
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 1,109 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 11,448 KB
実行使用メモリ 20,636 KB
最終ジャッジ日時 2023-08-26 14:23:32
合計ジャッジ時間 8,647 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,180 KB
testcase_01 AC 80 ms
15,020 KB
testcase_02 AC 81 ms
15,112 KB
testcase_03 AC 77 ms
15,132 KB
testcase_04 AC 78 ms
15,200 KB
testcase_05 AC 80 ms
15,140 KB
testcase_06 AC 77 ms
15,296 KB
testcase_07 AC 75 ms
15,216 KB
testcase_08 AC 75 ms
15,224 KB
testcase_09 AC 75 ms
15,120 KB
testcase_10 AC 78 ms
15,128 KB
testcase_11 AC 74 ms
15,104 KB
testcase_12 AC 76 ms
15,264 KB
testcase_13 AC 113 ms
15,220 KB
testcase_14 AC 110 ms
15,388 KB
testcase_15 AC 77 ms
15,148 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:31: warning: `*' interpreted as argument prefix
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
def yield_from(*funcsyms)
	funcsyms.each{|funcsym|
		func = method(funcsym)
		define_method(funcsym){|*args,&blk|
			return to_enum(funcsym,*args) if !blk
			func.(*args){|*a|a.each{|e|blk.(e)}}
		}
	}
end

if false
	require 'prime'
	def prime_division(n) n.prime_division end
else
	def prime_division(n)
		IO.popen('factor '+n.to_s){|io|
			a=[]
			line=io.gets
			line.split[1..-1].group_by{|e|e}.each{|k,v|a<<[k.to_i,v.size]}
			a
		}
	end
end
def divisor_totient(a,d,n,t)
	return to_enum(:divisor,a,d,n,t) if !block_given?
	if d==a.size
		yield [n,t]
	else
		(0..a[d][1]).each{|i|
			yield *divisor_totient(
				a,d+1,
				n*a[d][0]**i,
				i==0 ? t : t*(a[d][0]-1)*a[d][0]**(i-1)
			)
		}
	end
end
yield_from :divisor_totient
def pow(x,y,m)
	z=1
	while y>0
		z=z*x%m if y%2>0
		x=x*x%m
		y/=2
	end
	z
end

cache={}
M=1000000007
H,W,K=gets.split.map(&:to_i)
A=prime_division(H)
B=prime_division(W)
r=0
divisor_totient(A,0,1,1){|a,at|
	divisor_totient(B,0,1,1){|b,bt|
		key=W*H/a.lcm(b)
		cache[key]=pow(K,key,M) if !cache.has_key?(key)
		r=(r+at*bt*cache[key])%M
	}
}
p r*pow(W*H,M-2,M)%M
0