mfgnik

Untitled

Jun 8th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. def factorization(n):
  2. p = []
  3. d = 2
  4. while d * d <= n:
  5. cnt = 0
  6. while n % d == 0:
  7. cnt += 1
  8. n //= d
  9. if cnt != 0:
  10. p.append([d, cnt])
  11. d += 1
  12. if n > 1:
  13. p.append([n, 1])
  14. return p
  15.  
  16.  
  17. def print_summand(summand):
  18. prime, degree = summand
  19. if degree > 1:
  20. return '{}^{}'.format(prime, degree)
  21. return str(prime)
  22.  
  23.  
  24. print('*'.join(map(print_summand, factorization(int(input())))))
Advertisement
Add Comment
Please, Sign In to add comment