MOD = 10 ** 9 + 7 modinv = lambda a, mod=MOD: pow(a, mod - 2, mod) def solve(N, K, M): if M == 1: return calc_1(N, K) else: return (pow(N, N, MOD) - calc_1(N, K)) * modinv(N - 1) % MOD def calc_1(N, K): res = 0 perm_tmp = 1 pow_table = create_pow_table(N) for i in range(1, N + 1): if not K % i: res += perm_tmp * pow_table[N - i] perm_tmp *= N - i perm_tmp %= MOD res %= MOD return res def create_pow_table(length: int) -> list: pow_table = [1] * length for i in range(1, length): pow_table[i] = pow_table[i - 1] * length % MOD return pow_table print(solve(*map(int, input().split())))