Calculates a list of totients from 0 to max_one exclusive, using the definition of Euler's product formula. >>> get_totients(5) [0, 1, 1, 2, 2] >>> get_totients(10) [0, 1, 1, 2, 2, 4, 2, 6, 4, 6]
(max_one: int)
| 35 | |
| 36 | |
| 37 | def get_totients(max_one: int) -> list[int]: |
| 38 | """ |
| 39 | Calculates a list of totients from 0 to max_one exclusive, using the |
| 40 | definition of Euler's product formula. |
| 41 | |
| 42 | >>> get_totients(5) |
| 43 | [0, 1, 1, 2, 2] |
| 44 | |
| 45 | >>> get_totients(10) |
| 46 | [0, 1, 1, 2, 2, 4, 2, 6, 4, 6] |
| 47 | """ |
| 48 | totients = np.arange(max_one) |
| 49 | |
| 50 | for i in range(2, max_one): |
| 51 | if totients[i] == i: |
| 52 | x = np.arange(i, max_one, i) # array of indexes to select |
| 53 | totients[x] -= totients[x] // i |
| 54 | |
| 55 | return totients.tolist() |
| 56 | |
| 57 | |
| 58 | def has_same_digits(num1: int, num2: int) -> bool: |