Problem 42781. How many ways to write a number
Given two positive numbers n and k, where n>=k. In how many ways can we write n as sum of k positive numbers. Same numbers but different orders are considered different.
Example
For n=5, k=2 the answer is 4.
5 = 1 + 4
5 = 2 + 3
5 = 3 + 2
5 = 4 + 1
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Anupam Agarwal
on 22 Mar 2016
please correct the reference solution to com(x,k) instead of com(x)
Jihye Sofia Seo
on 12 Feb 2017
Please correct test cases, the function should have 2 arguments.
Ramon Villamangca
on 14 Dec 2021
Error message: Not enough input arguments.
Dyuman Joshi
on 14 Dec 2021
The test suite has been corrected.
Solution Comments
Show commentsProblem Recent Solvers24
Suggested Problems
-
Project Euler: Problem 8, Find largest product in a large string of numbers
1301 Solvers
-
Create matrix of replicated elements
395 Solvers
-
Create an index-powered vector
929 Solvers
-
715 Solvers
-
Find the position of first minimum value in an integer array with numbers
183 Solvers
More from this Author5
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!