Factorizing a number in Python

后端 未结 4 1310
灰色年华
灰色年华 2021-01-14 02:55

Here\'s my code:

def factorize(n):
    sieve = [True] * (n + 1)

    for x in range(2, int(len(sieve) ** 0.5) + 1):
        if sieve[x]: 
            for i i         


        
4条回答
  •  终归单人心
    2021-01-14 03:22

    My one-liner with python 3.8 (assignment expressions used)

    f = lambda n: (p:=[next(i for i in range(2, n+1) if n % i == 0)] if n>1 else [])+(f(n//p[0]) if p else [])
    

    video with details - Factorizing number in Python

提交回复
热议问题