Advertisement
Toumo

factorizacion_recursiva.py

Oct 22nd, 2022 (edited)
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | Source Code | 0 0
  1. def esPrimo(n: int) -> bool:
  2.     def menorDivisorDesde(n: int, m: int = 2) -> int:
  3.         if n == 1 or n == m: return n
  4.         if n%m == 0: return m
  5.         return menorDivisorDesde(n, m+1)
  6.     return n != 1 and n == menorDivisorDesde(n)
  7.  
  8. def factorizacion(n: int) -> list:
  9.     def factorizacionAux(n: int, m: int = 2) -> list:
  10.         if n == 1: return []
  11.         if n%m == 0 and esPrimo(m): return [m, *factorizacionAux(n//m, m)]
  12.         return factorizacionAux(n, m+1)
  13.     return factorizacionAux(n)
  14.  
  15. if __name__ == '__main__':
  16.     print(factorizacion(2*2*2*5*5*11*11*13*19)) # 5977400
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement