#include #include namespace nachia{ template struct StaticModint{ private: using u64 = unsigned long long; unsigned int x; public: using my_type = StaticModint; StaticModint() : x(0){} StaticModint(unsigned int v) : x(v){} unsigned int operator*() const { return x; } my_type& operator+=(const my_type& r){ auto t = x + r.x; if(t >= MOD) t -= MOD; x = t; return *this; } my_type operator+(const my_type& r) const { my_type res = *this; return res += r; } my_type& operator-=(const my_type& r){ auto t = x + MOD - r.x; if(t >= MOD) t -= MOD; x = t; return *this; } my_type operator-(const my_type& r) const { my_type res = *this; return res -= r; } my_type operator-() const { my_type res = *this; res.x = ((res.x == 0) ? 0 : (MOD - res.x)); return res; } my_type& operator*=(const my_type& r){ x = (u64)x * r.x % MOD; return *this; } my_type operator*(const my_type& r) const { my_type res = *this; return res *= r; } my_type pow(unsigned long long i) const { my_type a = *this, res = 1; while(i){ if(i & 1) res *= a; a *= a; i >>= 1; } return res; } my_type inv() const { return pow(MOD-2); } unsigned int val() const { return x; } static unsigned int get_mod() { return MOD; } my_type& operator/=(const my_type& r){ return operator*=(r.inv()); } my_type operator/(const my_type& r) const { return operator*(r.inv()); } }; } #include namespace nachia{ template struct MatrixModulo{ private: int h; int w; std::vector elems; public: MatrixModulo(int new_h, int new_w){ h = new_h; w = new_w; elems.assign(h * w, 0); } MatrixModulo(const MatrixModulo&) = default; int height() const { return h; } int width() const { return w; } typename std::vector::iterator operator[](int y){ return elems.begin() + (y * w); } typename std::vector::const_iterator operator[](int y) const { return elems.begin() + (y * w); } static MatrixModulo identity(int idx){ auto res = MatrixModulo(idx, idx); for(int i = 0; i < idx; i++) res[i][i] = 1; return res; } MatrixModulo operator*(const MatrixModulo& r) const { assert(w == r.h); auto res = MatrixModulo(h, r.w); for (int i=0; i=i; k--) g[j][k] -= g[j][i] * g[i][k]; } return ans; } int rank() const { MatrixModulo g = *this; int y = 0; for (int d=0; d=d; j--) g[i][j] -= g[i][d] * g[y][j]; y++; } return y; } MatrixModulo linear_equation() const { MatrixModulo g = *this; int y = 0; std::vector> det_var; std::vector rank_var; for (int d=0; d=d; j--) g[i][j] -= g[i][d] * g[y][j]; det_var.push_back(std::make_pair(d,y)); y++; } for (int i=y; i #include using namespace std; using i64 = long long; using u64 = unsigned long long; using i32 = int; using u32 = unsigned int; #define rep(i,n) for(int i=0; i<(n); i++) using modint = nachia::StaticModint<1000000007>; using matrix = nachia::MatrixModulo; modint f1(int k, u64 m){ if(k < 1) return 0; return modint(k) * modint(k-1).pow(m-1); } modint f2(int k, u64 m){ if(k < 2) return 0; if(k == 2) return 2; modint a = modint(k) * (k-1); modint b = a - modint(k*2-2) + 1; return a * b.pow(m-1); } modint f3(int k, u64 m){ if(k < 2) return 0; if(k == 2) return 2; matrix A(2,2); modint kP0 = modint(1); modint kP1 = modint(k); modint kP2 = modint(k) * (k-1); modint kP3 = modint(k) * (k-1) * (k-2); A[0][0] = modint(k-2) * (k-2) + (k-1); A[1][0] = modint(k-2) * (k-3) + (k-1); A[0][1] = ( modint(k-2) * (k-3) + (k-1) ) * (k-2); A[1][1] = modint(k) * (k-1) * (k-2) - modint(k-1) * (k-2) * 3 + modint(k-2) * 3 - 1; A = A.pow(m-1); return A[0][0] * kP2 + A[0][1] * kP2 + A[1][0] * kP3 + A[1][1] * kP3; } modint f(int n, int k, u64 m){ if(n == 1) return f1(k,m); if(n == 2) return f2(k,m); if(n == 3) return f3(k,m); return 0; } int main() { int N; cin >> N; u64 M; cin >> M; int K; cin >> K; modint ans = 0; vector F(K+1,1); for(int i=1; i<=K; i++) F[i]=F[i-1]*i; vector iF(K+1); iF[K] = F[K].inv(); for(int i=K; i>=1; i--) iF[i-1]=iF[i]*i; for(int k=0; k<=K; k++){ auto tmp = f(N,K-k,M) * F[K] * iF[k] * iF[K-k]; if(k % 2 == 0) ans += tmp; else ans -= tmp; } cout << *ans << endl; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;