Share your repls and programming experiences

← Back to all posts
##### Prime Factorization

I create a program that takes a number, any number, and converts it to a multiplication chain of prime numbers (example: 223*5). This process is called prime factorization and can be used to simplify calculating square roots by hand. It also has other uses. For some numbers, the program will say failed at the end because there is no prime factor multiplication chain that can make that number or there is but that chain includes primes outside of the range 2-11. The reason the range of primes is so small is because for each prime i add, the slower it is to compute the output (slower by a good amount). I find the chain by finding the minimum and maximum size of the chain and loop through all sizes in between. For each of these chain lengths, i find all combinations of 2s, 3s, 5s, 7s, and 11s, and check if when calculated, any of the chains equal the desired value. Some numbers that work are 4, 6, 12, 18, 16, 25, 32, 64, 72, 80, 81, 144, 288, ect... (It takes about 10 seconds on my desktop to find the chain for 72000000).