結果

問題 No.1253 雀見椪
ユーザー simansiman
提出日時 2022-05-16 12:32:49
言語 Ruby
(3.3.0)
結果
AC  
実行時間 452 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 11,296 KB
実行使用メモリ 15,412 KB
最終ジャッジ日時 2023-10-12 04:52:05
合計ジャッジ時間 8,201 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,040 KB
testcase_01 AC 79 ms
15,264 KB
testcase_02 AC 83 ms
15,040 KB
testcase_03 AC 106 ms
15,120 KB
testcase_04 AC 445 ms
15,204 KB
testcase_05 AC 446 ms
15,324 KB
testcase_06 AC 445 ms
15,412 KB
testcase_07 AC 446 ms
15,344 KB
testcase_08 AC 448 ms
15,336 KB
testcase_09 AC 448 ms
15,360 KB
testcase_10 AC 447 ms
15,172 KB
testcase_11 AC 445 ms
15,212 KB
testcase_12 AC 452 ms
15,184 KB
testcase_13 AC 441 ms
15,324 KB
testcase_14 AC 79 ms
15,240 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:28: warning: assigned but unused variable - a
Syntax OK

ソースコード

diff #

class Integer
  def mod_inverse(mod)
    self.pow(mod - 2, mod)
  end
end

T = gets.to_i
MOD = 10 ** 9 + 7

def f(n, a, b)
  c = (a + b)

  a1 = a.numerator.pow(n, MOD)
  a2 = a.denominator.pow(n, MOD)

  b1 = b.numerator.pow(n, MOD)
  b2 = b.denominator.pow(n, MOD)

  c1 = c.numerator.pow(n, MOD)
  c2 = c.denominator.pow(n, MOD)

  c1 * c2.mod_inverse(MOD) - a1 * a2.mod_inverse(MOD) - b1 * b2.mod_inverse(MOD)
end

T.times do
  n, ag, bg, ac, bc, ap, bp = gets.split.map(&:to_i)

  a = 3.pow(n, MOD).mod_inverse(MOD)

  g_rate = Rational(ag, bg)
  c_rate = Rational(ac, bc)
  p_rate = Rational(ap, bp)

  r1 = f(n, g_rate, c_rate)
  r2 = f(n, g_rate, p_rate)
  r3 = f(n, c_rate, p_rate)

  puts (1 - r1 - r2 - r3) % MOD
end
0