結果

問題 No.613 Solitude by the window
ユーザー cielciel
提出日時 2017-12-14 08:27:41
言語 Ruby
(3.3.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 294 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 11,484 KB
実行使用メモリ 15,372 KB
最終ジャッジ日時 2023-08-21 04:01:20
合計ジャッジ時間 3,996 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,348 KB
testcase_01 AC 82 ms
15,356 KB
testcase_02 AC 79 ms
15,348 KB
testcase_03 AC 79 ms
15,272 KB
testcase_04 AC 80 ms
15,160 KB
testcase_05 AC 83 ms
15,108 KB
testcase_06 AC 79 ms
15,148 KB
testcase_07 AC 80 ms
15,176 KB
testcase_08 AC 79 ms
15,156 KB
testcase_09 AC 79 ms
15,296 KB
testcase_10 AC 79 ms
15,172 KB
testcase_11 AC 78 ms
15,372 KB
testcase_12 AC 78 ms
15,244 KB
testcase_13 AC 80 ms
15,152 KB
testcase_14 AC 77 ms
15,040 KB
testcase_15 AC 78 ms
15,304 KB
testcase_16 AC 79 ms
15,244 KB
testcase_17 AC 79 ms
15,032 KB
testcase_18 AC 78 ms
15,344 KB
testcase_19 AC 81 ms
15,348 KB
testcase_20 AC 79 ms
15,148 KB
testcase_21 AC 80 ms
15,256 KB
testcase_22 AC 79 ms
15,340 KB
testcase_23 AC 79 ms
15,276 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
k,M=gets.split.map &:to_i
k=pow(2,k,M+(pow(3,M/2,M)==1?-1:1))
def mul(a,b)
	[(a[0]*b[0]+3*a[1]*b[1])%M,(a[1]*b[0]+b[1]*a[0])%M]
end
x=[2,1]
e=[1,0]
while k>0
	e=mul(e,x) if k%2>0
	x=mul(x,x)
	k/=2
end
p (2*e[0]-2)%M
0