• + 3 comments

    Thanks for that link. It made the problem easy. You need to satisfy two conditions: c<=a OR c<=b since the problem specified that ONE container held the desired quantity (if the quantity could be split across both containers then I guess this would be a much harder problem). The other condition is that c must be an integral multiple of gcd(a, b).

    My solution in lisp:

    (defun fillable (a b c)
        (cond ((and (> c a) (> c b)) nil)
            ((zerop (rem c (gcd a b))) T)
            (T nil)))
    
    (defun cases (n)
        (cond ((zerop n) nil)
            (T (if (fillable (read) (read) (read))
                   (format t "YES~%")
                   (format t "NO~%"))
               (cases (1- n)))))
    
    (cases (read))