A depot ships pallets using only three sizes of modular crates: 2-packs, 3-packs, and 5-packs. A pallet quantity is called modular-compatible if, starting from that quantity, you can repeatedly remove one full crate's worth -- dividing evenly by 2, 3, or 5, choosing whichever fits at each step -- and reach exactly 1 with nothing left over. Given a pallet quantity n, determine whether it is modular-compatible.
A single line containing one integer n.
Print "true" if n is modular-compatible, otherwise print "false".
Example 1
Input
30
Expected
true
Explanation
30 / 2 = 15, 15 / 3 = 5, 5 / 5 = 1, so 30 can be reduced to 1 using only crate sizes 2, 3, and 5: modular-compatible, output true.
Example 2
Input
14
Expected
false
Explanation
14 / 2 = 7, and 7 is not divisible by 2, 3, or 5, so the reduction gets stuck at 7 instead of reaching 1: output false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →