In the first part of series, we simplify the problem. Given two jugs with capacities A and B, and a target amount T, determine if it is mathematically possible to measure exactly T units in either jug.
Acording to Bezout's identity, you can only measure T if and only if:
- T is not greater than the capacity of the largest jug.
- T is a multiple of the greatest common divisor (GCD) of A and B.
Write a function tf = can_measure(A,B,T) that returns true or false
Examples:
- input: A = 3, B = 5, T = 4 -> output = true (GCD of 3 and 5 is 1, and 4 is a multiple of 1)
- input: A = 2, B = 4, T = 3 -> output = false (GCD of 2 and 4 is 2, but 3 is not a multiple of 2)
- input: A = 5, B = 10, T = 12 -> output = false (12 is greater than both jugs)
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers6
Suggested Problems
-
6 Solvers
More from this Author9
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!