Python Forum
Juicy highly composite number needs factorization
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Juicy highly composite number needs factorization
#8
Now with reverse:

#!/usr/bin/python3
import math


def primeFactors(n):
    list_factors = [ ]

    # print the number of two's that divide n
    while n % 2 == 0:
        print(2, end=",", flush=True)
        list_factors += [ 2 ]
        n = n // 2

    # n must be odd at this point.
    # so a skip of 2 (i = i + 2) can be used
    for i in range(3, int(math.sqrt(n))+1, 2):
        # while i divides n, print i ad divide n
        while n % i == 0:
            print(i, end=",", flush=True)
            list_factors += [ i ]
            n = n // i

    # condition if n is a prime
    # number greater than 2
    if n > 2:
        print(n, end=",", flush=True)
        list_factors += [ n ]

    print()
    return list_factors


def multiply(list_factors):
    res = 1
    for n in list_factors:
        res *= n
    return res


# main
n = 10334475851656087128243643125471284565310588797552748096314114788137761206785997576812685774304768000
print("number", n)

print("---")
list_factors = primeFactors(n)
print("---")

res = multiply(list_factors)
print("result", res)
print("---")

if n == res:
    print("OK")
else:
    print("ERROR")
#done
Reply


Messages In This Thread
RE: Juicy highly composite number needs factorization - by heiner55 - May-28-2019, 04:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python script to summarize excel tables, then output a composite table? i'm a total n surfer349 1 2,418 Feb-05-2021, 04:37 PM
Last Post: nilamo
  random fiber distribution for composite analysis pvdivakarraju 1 1,686 Jan-21-2021, 07:42 PM
Last Post: Larz60+
  How do I stop this fast factorization program from printing beyond the 3rd output? Pleiades 6 3,933 Dec-07-2019, 08:43 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020