Skip to the code
cf.
+10 XP

#648 Only Small Prime Factors

easy

An image service only produces thumbnail widths whose prime factors are all 2, 3, or 5, because those sizes scale cleanly.

Write isCleanSize(n) that returns true if n has no prime factor other than 2, 3, and 5, and false otherwise. 1 has no prime factors at all, so it counts as clean.

Example 1

Input: n = 30
Output: true

30 = 2 × 3 × 5.

Example 2

Input: n = 14
Output: false

14 = 2 × 7, and 7 is not allowed.

Constraints

  • 1 <= n <= 2^31 - 1
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).