結果

問題 No.1136 Four Points Tour
ユーザー 小野寺健
提出日時 2021-11-03 10:27:17
言語 Ruby
(3.4.1)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 271 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-10-12 23:00:59
合計ジャッジ時間 4,780 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
M = 10**9 + 7

def mod_pow(x, n, m)
	res = 1
	while n > 0 do
		if n & 1 != 0 then
			res = res * x % m
		end
		x = x * x % m
		n >>= 1
	end
	res
end

a = mod_pow(3, N-1, M)
b = N % 2 == 0 ? 1 : -1
c = (a + b) * mod_pow(4, M-2, M) % M
d = (c * 3) % M

puts d
0