Problem 55235. Determine if x is a combination of m and n
Given positive integers x, m, and n, determine if x can be written as x = am + bn for any (non-negative) integers a and b. Your function should return logical true or false.
For example
- iscombo(17,3,5) should return true because 17 = 4*3 + 1*5
- iscombo(18,3,5) should return true because 18 = 6*3 + 0*5
- iscombo(7,3,5) should return false because 7 cannot be written as a combination of 3 & 5 (7 is not divisible by either 3 or 5 and 1*3 + 1*5 = 8)
Hint: You can start by calculating all possible values of combining m and n
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
Tim
on 3 Oct 2022
The last test case still has "assert(a*m+b*n,m,n)" instead of "assert(iscombo(a*m+b*n,m,n))". Also, I found it more convenient to have the first test cases all together, as they were originally, to copy them more easily.
Dyuman Joshi
on 4 Oct 2022
I understand your point Tim, however, individual test cases will help people to find where their code is failing.
I have corrected the last test case and rescored the solutions.
Matt Tearle
on 4 Oct 2022
Thanks for catching and fixing that - internet cookies all round!
Solution Comments
Show commentsProblem Recent Solvers331
Suggested Problems
-
Create a cell array out of a struct
2082 Solvers
-
299 Solvers
-
Cell Counting: How Many Draws?
2125 Solvers
-
Integer Sequence - II : New Fibonacci
567 Solvers
-
1757 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!