Forked from AspirantDrago/Задача №1455. Разложение на простые.py
Created
August 19, 2023 07:47
-
-
Save xxDmitrix/f0b05e4b1cc08dfc9a82ae05984774b8 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