For example, for N = 7, M = 3, K = 3, the result is
1 + 3 + 3
3 + 1 + 3
3 + 3 + 1
2 + 2 + 3
2 + 3 + 2
3 + 2 + 2
Total 6
according to the comment of JMoravitz, I tried to solve it using generating function. But is there any way to find the co-efficient of x^n more efficiently? For example, when N = 1000000000000000000, M = 11111111112, k = 90000000? I need to find no of ways mod m