結果

問題 No.1844 Divisors Sum Sum
ユーザー yudedakoyudedako
提出日時 2022-02-28 20:38:41
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,562 ms / 3,000 ms
コード長 3,020 bytes
コンパイル時間 14,725 ms
コンパイル使用メモリ 257,996 KB
実行使用メモリ 78,440 KB
最終ジャッジ日時 2023-09-21 05:08:31
合計ジャッジ時間 63,272 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,540 ms
78,168 KB
testcase_01 AC 1,500 ms
78,384 KB
testcase_02 AC 1,544 ms
78,320 KB
testcase_03 AC 1,537 ms
78,204 KB
testcase_04 AC 1,537 ms
78,284 KB
testcase_05 AC 1,528 ms
78,344 KB
testcase_06 AC 1,543 ms
78,144 KB
testcase_07 AC 1,538 ms
78,000 KB
testcase_08 AC 1,562 ms
78,132 KB
testcase_09 AC 1,534 ms
78,440 KB
testcase_10 AC 1,511 ms
77,252 KB
testcase_11 AC 1,255 ms
64,724 KB
testcase_12 AC 1,425 ms
75,020 KB
testcase_13 AC 1,201 ms
62,628 KB
testcase_14 AC 1,294 ms
66,980 KB
testcase_15 AC 939 ms
62,128 KB
testcase_16 AC 933 ms
61,552 KB
testcase_17 AC 942 ms
61,756 KB
testcase_18 AC 932 ms
62,164 KB
testcase_19 AC 948 ms
61,908 KB
testcase_20 AC 949 ms
61,920 KB
testcase_21 AC 933 ms
62,572 KB
testcase_22 AC 949 ms
61,952 KB
testcase_23 AC 958 ms
61,480 KB
testcase_24 AC 946 ms
61,872 KB
testcase_25 AC 951 ms
61,928 KB
testcase_26 AC 950 ms
62,328 KB
testcase_27 AC 963 ms
61,804 KB
testcase_28 AC 993 ms
62,272 KB
testcase_29 AC 939 ms
62,296 KB
testcase_30 AC 953 ms
62,008 KB
testcase_31 AC 961 ms
62,004 KB
testcase_32 AC 958 ms
62,236 KB
testcase_33 AC 949 ms
61,924 KB
testcase_34 AC 950 ms
61,820 KB
testcase_35 AC 934 ms
61,936 KB
testcase_36 AC 944 ms
61,912 KB
testcase_37 AC 987 ms
61,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.collection.mutable.*
import scala.io.StdIn.*
import scala.util.chaining.*
import scala.math.*
import scala.reflect.ClassTag
import scala.util.*
import scala.annotation.tailrec
import scala.collection.mutable



object ModInt:
  opaque type ModInt = Long
  inline def zero: ModInt = 0
  inline def one: ModInt = 1
  extension (value: Long)
    inline def toModInt(using inline mod: Int): ModInt =  value % mod
    inline def unsafeAsModInt: ModInt = value
  extension (value: Int)
    inline def toModInt(using inline mod: Int): ModInt = value % mod
    inline def unsafeAsModInt: ModInt = value
  trait Converter[T]:
    inline def convert(value: T)(using inline mod: Int): ModInt
  inline given Converter[Int] with
    override inline def convert(value: Int)(using inline mod: Int) = value.toModInt
  inline given Converter[Long] with
    override inline def convert(value: Long)(using inline mod: Int) = value.toModInt
  inline given Converter[ModInt] with
    override inline def convert(value: ModInt)(using inline mod: Int) = value
  extension (modInt: ModInt)
    inline def toLong(using inline mod: Int): Long = (modInt + mod) % mod
    inline def rawValue: Long = modInt
    inline def inverse(using inline mod: Int): ModInt =
      var x = modInt
      var y = mod.toLong
      var a = 1L
      var b = 0L
      var c = 0L
      var d = 1L
      while y != 0 do
        val q = x / y
        val e = a - c * q
        val f = b - d * q
        a = c
        b = d
        c = e
        d = f
        x = y
        y = c * modInt + d * mod
      require(x.abs == 1L)
      if x == 1 then a % mod else -a % mod
    inline def powMod(exp: Long)(using inline mod: Int): ModInt =
      var result = 1L
      var base = modInt
      var e = exp
      while e > 0 do
        if (e & 1) == 1 then
          result = result * base % mod
        base = base * base % mod
        e >>= 1
      result
    inline def powMod(exp: Int)(using inline mod: Int): ModInt = powMod(exp.toLong)
  extension [L: Converter, R: Converter] (left: L)
    inline def +(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) + summon[Converter[R]].convert(right)).toModInt
    inline def -(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) - summon[Converter[R]].convert(right)).toModInt
    inline def *(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) * summon[Converter[R]].convert(right)).toModInt
    inline def /(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) * summon[Converter[R]].convert(right).inverse).toModInt

@main def main =
  import ModInt.*
  inline given mod: Int = 1000000007
  val l = readLine.toInt
  val primeFactor = Array.fill(l){
    val Array(p, e) = readLine.split(' ').map(_.toInt)
    p.unsafeAsModInt -> e
  }
  val result = primeFactor.foldLeft(1.unsafeAsModInt){case (acc, (p, e)) => acc * (p.powMod(e + 2) - (e + 2) * p + e + 1) / ((p - 1) * (p - 1)) }
  println(result.toLong)
0