+ 7

Challenge: Factorize factorial numbers as product of prime numbers

Create a program that receives a positive integer number and factorize the factorial of that number as a product of prime numbers. In other words, the program must receive a natural number 'n', and show the factorization as a product of prime numbers of 'n!' (factorial of 'n'). Example 1: Input: 8 Output: 8! = 2^7 * 3^2 * 5^1 * 7^1 Example 2: Input: 50 Output: 50! = 2^47 * 3^22 * 5^12 * 7^8 * 11^4 * 13^3 * 17^2 * 19^2 * 23^2 * 29^1 * 31^1 * 37^1 * 41^1 * 43^1 * 47^1 Example 3: Input: 100 Output: 100! = 2^97 * 3^48 * 5^24 * 7^16 * 11^9 * 13^7 * 17^5 * 19^5 * 23^4 * 29^3 * 31^3 * 37^2 * 41^2 * 43^2 * 47^2 * 53^1 * 59^1 * 61^1 * 67^1 * 71^1 * 73^1 * 79^1 * 83^1 * 89^1 * 97^1 Factorial: https://en.wikipedia.org/wiki/Factorial Prime number: https://en.wikipedia.org/wiki/Prime_number

17th Nov 2017, 2:31 AM
Miguel Zabala
Miguel Zabala - avatar
8 Answers
+ 15
Thank you for the beautiful challenge 👍👏 Here's my try : https://code.sololearn.com/c1lN2W7OMsbb/?ref=app
17th Nov 2017, 9:33 PM
LukArToDo
LukArToDo - avatar
+ 5
Thanks for the challenge one could do a lot of performance improvment So the factorials of n cant be factorials of n+1 well ...here is m basic solution https://code.sololearn.com/cCrtDXQPCvXG/?ref=app
19th Nov 2017, 7:54 AM
Oma Falk
Oma Falk - avatar
17th Nov 2017, 11:48 AM
~ MasouD
~ MasouD - avatar
18th Nov 2017, 10:27 PM
VcC
VcC - avatar
+ 2
I avoided having to calculate the factorial. Hence it works for numbers even as high as 3000 and only stops on 10000 because of the time limit. https://code.sololearn.com/cTeTGyL37QXZ/#java
19th Nov 2017, 6:23 AM
Bill Fisher
19th Nov 2017, 8:44 AM
VcC
VcC - avatar
20th Nov 2017, 11:24 AM
Hiroki Masuda
Hiroki Masuda - avatar
0
O(n.loglogn) complexity. Works for very large n like 20000 or higher
18th Nov 2017, 10:54 PM
VcC
VcC - avatar