結果

問題 No.2 素因数ゲーム
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-04-01 10:24:10
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 517 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 11,088 KB
実行使用メモリ 15,316 KB
最終ジャッジ日時 2023-08-27 04:53:24
合計ジャッジ時間 4,450 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,316 KB
testcase_01 AC 81 ms
15,272 KB
testcase_02 AC 81 ms
15,140 KB
testcase_03 AC 81 ms
15,236 KB
testcase_04 AC 81 ms
15,128 KB
testcase_05 AC 82 ms
15,184 KB
testcase_06 AC 80 ms
15,144 KB
testcase_07 AC 82 ms
15,136 KB
testcase_08 AC 78 ms
15,204 KB
testcase_09 AC 83 ms
15,180 KB
testcase_10 AC 80 ms
15,208 KB
testcase_11 AC 79 ms
15,132 KB
testcase_12 AC 80 ms
15,044 KB
testcase_13 AC 80 ms
15,184 KB
testcase_14 AC 79 ms
15,032 KB
testcase_15 AC 81 ms
15,084 KB
testcase_16 AC 79 ms
15,276 KB
testcase_17 AC 81 ms
15,064 KB
testcase_18 AC 81 ms
15,024 KB
testcase_19 AC 81 ms
15,088 KB
testcase_20 AC 80 ms
15,100 KB
testcase_21 AC 81 ms
15,272 KB
testcase_22 AC 81 ms
15,184 KB
testcase_23 AC 79 ms
15,184 KB
testcase_24 AC 80 ms
15,136 KB
testcase_25 AC 82 ms
15,092 KB
testcase_26 AC 80 ms
15,148 KB
testcase_27 AC 79 ms
15,252 KB
testcase_28 AC 80 ms
15,104 KB
testcase_29 AC 82 ms
15,180 KB
testcase_30 AC 81 ms
15,152 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(n,arr,dp,v)
	if n==1
		return v
	else
		if dp.key?([v,n])!=false
			return dp[[v,n]]
		end
		
		arr.size.times{|i|
			t=arr[i]
			if n%t==0
				s=f(n/t,arr,dp,1-v)
				if v!=s
					dp[[v,n]]=s
					return s
				end
			end
		}
		dp[[v,n]]=v
		return dp[[v,n]]
	end
end


n=gets.to_i
n2=n
d=2
arr=[]
while d*d<=n
	if n%d==0
		d2=d
		while n%d == 0
			n/=d
			arr<<d2
			d2*=d
		end
		
	end
	d+=1
end
if n>1
	arr<<n
end
arr=arr.uniq
dp={}
if arr.size==0
	puts "Alice"
else
	puts ["Bob","Alice"][f(n2,arr,dp,0)]
end
0