結果

問題 No.435 占い(Extra)
ユーザー cielciel
提出日時 2016-10-18 01:02:10
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 468 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 23,296 KB
最終ジャッジ日時 2024-04-17 02:43:04
合計ジャッジ時間 10,969 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
23,296 KB
testcase_01 AC 133 ms
17,664 KB
testcase_02 AC 133 ms
18,432 KB
testcase_03 AC 135 ms
17,664 KB
testcase_04 AC 140 ms
17,792 KB
testcase_05 AC 137 ms
17,792 KB
testcase_06 AC 145 ms
18,560 KB
testcase_07 AC 136 ms
17,792 KB
testcase_08 AC 145 ms
17,408 KB
testcase_09 AC 137 ms
17,408 KB
testcase_10 AC 179 ms
17,664 KB
testcase_11 AC 180 ms
17,536 KB
testcase_12 RE -
testcase_13 AC 552 ms
17,920 KB
testcase_14 AC 543 ms
17,792 KB
testcase_15 AC 546 ms
18,560 KB
testcase_16 AC 624 ms
21,376 KB
testcase_17 AC 1,088 ms
21,376 KB
testcase_18 RE -
testcase_19 AC 546 ms
17,920 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
I=[nil,1,5,nil,7,2,nil,4,8]
def z(n)
	r=0
	while n%3==0
		r+=1
		n/=3
	end
	[n,r]
end
def comb(n,k)
	k0,z0=F[n]
	k1,z1=F[k]
	k2,z2=F[n-k]
	z=z0-z1-z2
	r=k0*I[k1]*I[k2]%9
	#[r,r*3%9][z]||0
	r*3**z%9
end

F=[[1,0]]
(1..100000).each{|i|
	k0,z0=F[i-1]
	k1,z1=z(i)
	F[i]=[k0*k1%9,z0+z1]
}
gets.to_i.times{
	n,x,a,b,m=gets.split.map(&:to_i)
	r=0
	f=true
	n.times{|i|
		c=x%10
		r=(r+c*comb(n-1,i))%9
		f=false if c!=0
		x=((x^a)+b)%m
	}
	p r!=0||f ? r : 9
}
0