結果

問題 No.1671 Permutation Tour
ユーザー simansiman
提出日時 2021-12-25 19:19:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 312 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 11,776 KB
実行使用メモリ 16,280 KB
最終ジャッジ日時 2023-10-21 20:55:53
合計ジャッジ時間 2,574 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
16,276 KB
testcase_01 AC 93 ms
16,276 KB
testcase_02 AC 92 ms
16,276 KB
testcase_03 AC 93 ms
16,280 KB
testcase_04 AC 92 ms
16,276 KB
testcase_05 AC 94 ms
16,276 KB
testcase_06 AC 93 ms
16,276 KB
testcase_07 AC 93 ms
16,276 KB
testcase_08 AC 93 ms
16,276 KB
testcase_09 AC 93 ms
16,276 KB
testcase_10 AC 92 ms
16,276 KB
testcase_11 AC 94 ms
16,276 KB
testcase_12 AC 94 ms
16,276 KB
testcase_13 AC 94 ms
16,276 KB
testcase_14 AC 93 ms
16,276 KB
testcase_15 AC 93 ms
16,276 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Integer
  def mod_pow(n, mod)
    x = self
    res = 1

    while n > 0
      res = res * x % mod if n[0] == 1
      x = x * x % mod
      n >>= 1
    end

    res
  end

  def mod_inverse(mod)
    mod_pow(mod - 2, mod)
  end
end

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

pp N * (N + 1) * 3.mod_inverse(MOD) % MOD
0