#include #include #include using namespace std; using ll = long long; template using grid = vector>; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define input(...) __VA_ARGS__; in(__VA_ARGS__) void print() { std::cout << std::endl; } template void print(Head&& head, Tail&&... tail) { std::cout << head << " "; print(std::forward(tail)...); } void in() { } template void in(Head&& head, Tail&&... tail) { cin >> head; in(std::forward(tail)...); } int P; int f(int n, int k) { if (k == 0) return n == 0; int ans = 0; REP(i, P) { int v1 = f((n + i) % P, k - 1); int v2 = f((n * i) % P, k - 1); print(n, k, i, "+:", v1); print(n, k, i, "*:", v2); ans += v1 + v2; } return ans; } ll MOD = 1'000'000'000 + 7; ll mod(ll v) { if (v >= MOD) return v % MOD; return v % MOD; } int main() { int input(p, k); P = p; ll zero_pattern = 1; ll other_pattern = 0; ll to_zero = 0; ll to_other = 0; REP(i, k) { to_zero = mod(zero_pattern * (p + 1) + other_pattern * 2); to_other = mod(zero_pattern * (p - 1)) + mod(other_pattern * (p - 1 + p - 1)); zero_pattern = to_zero; other_pattern = to_other; } print(zero_pattern); }