All problems
0556EasyMath

Reachable Batch Size

Tracked in this browser only
Write code

Trains the technique from

LeetCode 263Ugly Number

This 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.

Examples

Example 1

Input
n = 4050
Output
true

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

Input
n = 385
Output
false

385 units would need a device that multiplies by 7 and another that multiplies by 11, and the line has neither.

Example 3

Input
n = -720
Output
false

The line only ever reports positive counts, so a negative target cannot be produced.

Constraints

  • -2^31 <= n <= 2^31 - 1

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def is_ugly(n: int) -> bool:
Java
public boolean isUgly(int n)
September 7
Apply