結果

問題 No.1259 スイッチ
ユーザー yuruhiyayuruhiya
提出日時 2020-10-17 10:25:48
言語 Crystal
(1.11.2)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,607 bytes
コンパイル時間 19,123 ms
コンパイル使用メモリ 254,732 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-13 12:16:59
合計ジャッジ時間 20,739 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,448 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,460 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,504 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 17 ms
4,392 KB
testcase_12 AC 11 ms
4,388 KB
testcase_13 AC 8 ms
4,392 KB
testcase_14 AC 10 ms
4,384 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 10 ms
4,384 KB
testcase_18 AC 17 ms
4,376 KB
testcase_19 AC 16 ms
4,376 KB
testcase_20 AC 13 ms
4,408 KB
testcase_21 AC 18 ms
4,380 KB
testcase_22 AC 6 ms
4,408 KB
testcase_23 AC 16 ms
4,420 KB
testcase_24 AC 12 ms
4,380 KB
testcase_25 AC 13 ms
4,380 KB
testcase_26 AC 17 ms
4,380 KB
testcase_27 AC 14 ms
4,376 KB
testcase_28 AC 12 ms
4,376 KB
testcase_29 AC 15 ms
4,380 KB
testcase_30 AC 10 ms
4,380 KB
testcase_31 AC 13 ms
4,380 KB
testcase_32 AC 7 ms
4,376 KB
testcase_33 AC 18 ms
4,492 KB
testcase_34 AC 11 ms
4,456 KB
testcase_35 AC 15 ms
4,376 KB
testcase_36 AC 14 ms
4,380 KB
testcase_37 AC 13 ms
4,376 KB
testcase_38 AC 12 ms
4,376 KB
testcase_39 AC 17 ms
4,464 KB
testcase_40 AC 18 ms
4,380 KB
testcase_41 AC 15 ms
4,376 KB
testcase_42 AC 18 ms
4,380 KB
testcase_43 AC 12 ms
4,380 KB
testcase_44 AC 17 ms
4,376 KB
testcase_45 AC 19 ms
4,380 KB
testcase_46 AC 11 ms
4,412 KB
testcase_47 AC 19 ms
4,376 KB
testcase_48 AC 10 ms
4,380 KB
testcase_49 AC 18 ms
4,376 KB
testcase_50 AC 11 ms
4,384 KB
testcase_51 AC 7 ms
4,384 KB
testcase_52 AC 17 ms
4,492 KB
testcase_53 AC 10 ms
4,376 KB
testcase_54 AC 18 ms
4,380 KB
testcase_55 AC 7 ms
4,376 KB
testcase_56 AC 10 ms
4,384 KB
testcase_57 AC 16 ms
4,420 KB
testcase_58 AC 11 ms
4,376 KB
testcase_59 AC 13 ms
4,380 KB
testcase_60 AC 18 ms
4,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

struct ModInt
  @@MOD = 1_000_000_007i64

  def self.mod
    @@MOD
  end

  def self.zero
    ModInt.new(0)
  end

  def initialize(n)
    @n = n.to_i64 % @@MOD
  end

  getter n : Int64

  def + : self
    self
  end

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

  def +(m)
    ModInt.new(@n + m.to_i64 % @@MOD)
  end

  def -(m)
    ModInt.new(@n - m.to_i64 % @@MOD)
  end

  def *(m)
    ModInt.new(@n * m.to_i64 % @@MOD)
  end

  def /(m)
    raise DivisionByZeroError.new if m == 0
    a, b, u, v = m.to_i64, @@MOD, 1i64, 0i64
    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)
    self / m
  end

  def **(m : Int)
    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_i64
  end

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

  def succ
    self + 1
  end

  def pred
    self - 1
  end

  def to_i64 : Int64
    @n
  end

  delegate to_s, to: @n
  delegate inspect, to: @n
end

struct Int
  def to_mint : ModInt
    ModInt.new(self)
  end
end

class String
  def to_mint : ModInt
    ModInt.new(self)
  end
end

n, k, m = read_line.split.map(&.to_i64)

x = ModInt.zero
(1..n).reduce(1.to_mint) { |acc, i|
  if k % i == 0 && i <= n
    x += acc * n.to_mint ** (n - i)
  end
  acc * (n - i)
}

if m == 1
  puts x
else
  puts (n.to_mint**n - x) / (n - 1)
end
0