結果

問題 No.673 カブトムシ
ユーザー yuruhiyayuruhiya
提出日時 2020-09-17 17:02:08
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,031 bytes
コンパイル時間 63 ms
コンパイル使用メモリ 11,444 KB
実行使用メモリ 15,336 KB
最終ジャッジ日時 2023-09-04 07:22:21
合計ジャッジ時間 2,556 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 84 ms
15,072 KB
testcase_03 AC 84 ms
15,216 KB
testcase_04 AC 84 ms
15,336 KB
testcase_05 AC 86 ms
15,136 KB
testcase_06 AC 84 ms
15,292 KB
testcase_07 AC 83 ms
15,028 KB
testcase_08 AC 84 ms
15,076 KB
testcase_09 AC 85 ms
15,068 KB
testcase_10 AC 82 ms
15,216 KB
testcase_11 AC 84 ms
15,260 KB
testcase_12 AC 84 ms
15,272 KB
testcase_13 AC 86 ms
15,084 KB
testcase_14 AC 85 ms
15,068 KB
testcase_15 AC 87 ms
15,280 KB
testcase_16 AC 85 ms
15,156 KB
testcase_17 AC 84 ms
15,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class ModInt
	@@mod = 1_000_000_007

	def initialize(n)
		@n = n.to_i % @@mod
	end

	def self.zero
		ModInt.new(0)
	end

	def self.mod
		@@mod
	end

	def self.mod=(m)
		@@mod = m.to_i
	end

	def +@
		self
	end

	def -@
		ModInt.new(n != 0 ? @@mod - @n : 0)
	end

	def +(m)
		ModInt.new(@n + m.to_i % @@mod)
	end

	def -(m)
		ModInt.new(@n - m.to_i % @@mod)
	end

	def *(m)
		ModInt.new(@n * m.to_i % @@mod)
	end

	def /(m)
		raise DivisionByZeroError.new if m == 0
		a, b, u, v = m.to_i, @@mod, 1, 0
		while b != 0
			t = a / b
			a -= t * b
			a, b = b, a
			u -= t * v
			u, v = v, u
		end
		ModInt.new(@n * u)
	end

	def **(m)
		t, res = self, ModInt.new(1)
		while m > 0
			res *= t if m.odd?
			t *= t
			m >>= 1
		end
		res
	end

	def ==(m)
		@n == m.to_i
	end

	def !=(m)
		@n != m.to_i
	end

	def succ
		self + 1
	end

	def pred
		self - 1
	end

	def to_i
		@n
	end

	def to_s
		@n.to_s
	end
end

b, c, d = gets.split.map(&:to_i)
if c == 1
	puts ModInt.new(b) * d
else
	puts (ModInt.new(c) ** d.succ - c) / (c - 1) * b
end
0