> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Ugly Number Python Solution with Tests

> Tested Python solution for LeetCode 263 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 263, [Easy](/catalog/easy). Topics: [Math](/catalog/topics/math). [View on LeetCode](https://leetcode.com/problems/ugly-number/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 263   # by problem number
lcpy gen -s ugly_number   # by problem name
```

## Problem

An ugly number is a positive integer which does not have a prime factor other than 2, 3, and 5.

Given an integer `n`, return `true` if `n` is an ugly number.

### Examples

```
Input: n = 6
Output: true
Explanation: 6 = 2 × 3
```

```
Input: n = 1
Output: true
Explanation: 1 has no prime factors.
```

```
Input: n = 14
Output: false
Explanation: 14 is not ugly since it includes the prime factor 7.
```

### Constraints

* -2^31 \<= n \<= 2^31 - 1

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/ugly_number/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/ugly_number/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(log n)
    # Space: O(1)
    def is_ugly(self, n: int) -> bool:
        if n <= 0:
            return False
        for p in (2, 3, 5):
            while n % p == 0:
                n //= p
        return n == 1
```

## Complexity

| Time | Space |
| - | - |
| O(log n) | O(1) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.