Recognize Positive Numbers with Only Three Allowed Prime Factors

Quick Overview

Recognize Positive Numbers with Only Three Allowed Prime Factors. A positive ugly number has no prime factors outside 2, 3 and 5. Return whether n is ugly; 1 qualifies because it has no prime factors.

Recognize Positive Numbers with Only Three Allowed Prime Factors

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem A positive ugly number has no prime factors outside 2, 3 and 5. Return whether n is ugly; 1 qualifies because it has no prime factors. ```cpp bool isUgly(int n); ``` ### Examples ```text n = 30 -> true n = 22 -> false ``` ### Constraints - n is any signed 32-bit integer.

Overview: Recognize Positive Numbers with Only Three Allowed Prime Factors. A positive ugly number has no prime factors outside 2, 3 and 5. Return whether n is ugly; 1 qualifies because it has no prime factors.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

A positive ugly number has no prime factors outside 2, 3 and 5. Return whether n is ugly; 1 qualifies because it has no prime factors.

bool isUgly(int n);

Examples

n = 30 -> true
n = 22 -> false

Constraints

  • n is any signed 32-bit integer.