MOD = 10**9 + 7 class Integer def modpow(n) if n.zero? 1 elsif n.odd? self * self.modpow(n - 1) % MOD else (self * self % MOD).modpow(n / 2) end end def inverse self.modpow(MOD - 2) end end def nPr(n, r) value = 1 r.times do |i| value = value * (n - i) % MOD end value end def fact(n) nPr(n, n) end n, k, m = gets.split.map(&:to_i) one = 0 (1 .. n).each do |i| if k % i == 0 one += nPr(n - 1, i - 1) * n.modpow(n - i) end end one %= MOD if m == 1 puts one else puts ((n.modpow(n) - one) * (n - 1).inverse) % MOD end