Created
January 14, 2023 18:28
-
-
Save AspirantDrago/eb607855a3e658b4f8c91f19d3625fc3 to your computer and use it in GitHub Desktop.
Задача №1455. Разложение на простые
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
| # Задача №1455. Разложение на простые | |
| ''' | |
| Требуется разложить целое число N на простые множители и вывести результат в порядке возрастания. | |
| Входные данные | |
| Программе дано число N (2 ≤ N ≤ 109). | |
| Выходные данные | |
| Вывести разложение N на простые множители | |
| ''' | |
| n = int(input()) | |
| answer = [] | |
| i = 2 | |
| while i * i <= n: | |
| count = 0 | |
| while n % i == 0: | |
| n //= i | |
| count += 1 | |
| if count == 1: | |
| answer.append(str(i)) | |
| elif count > 1: | |
| answer.append(f'{i}^{count}') | |
| i += 1 | |
| if n > 1: | |
| answer.append(str(n)) | |
| print('*'.join(answer)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment