Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AspirantDrago/eb607855a3e658b4f8c91f19d3625fc3 to your computer and use it in GitHub Desktop.

Select an option

Save AspirantDrago/eb607855a3e658b4f8c91f19d3625fc3 to your computer and use it in GitHub Desktop.
Задача №1455. Разложение на простые
# Задача №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