Last active
August 13, 2025 07:08
-
-
Save bru32/e452bd012e9864b3a7f987217fa937f2 to your computer and use it in GitHub Desktop.
Best way to get all factors of a number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Get all the factors of a number. | |
| Bruce Wernick | |
| 13 August 2025 | |
| """ | |
| import math | |
| def get_factors(n): | |
| arr = set() | |
| for i in range(1, int(1 + math.sqrt(n))): | |
| if n % i == 0: | |
| arr.add(i) | |
| arr.add(n // i) | |
| return sorted(arr) | |
| print(get_factors(840)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment