Trains the technique from
LeetCode 263Ugly NumberThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A crating line assembles an order by starting from one single unit and then applying a sequence of doublers, triplers and quintuplers: each device in the line multiplies the running count by 2, by 3 or by 5. Devices may be used in any order and any number of times, and the line may also be left empty.
A count n is reachable when some arrangement of those devices produces exactly n units. The count 1 is reachable, since the empty line already delivers one unit.
Given an integer n, return true when n is reachable and false when it is not. The line never produces zero or a negative count, so any n that is not strictly positive is unreachable.
Example 1
One doubler, four triplers and two quintuplers turn the single starting unit into 2 * 81 * 25 = 4050 units, so the count is reachable.
Example 2
385 units would need a device that multiplies by 7 and another that multiplies by 11, and the line has neither.
Example 3
The line only ever reports positive counts, so a negative target cannot be produced.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def is_ugly(n: int) -> bool:public boolean isUgly(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.