An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
July 4, 2019 02:00 pm GMT
Original Link: https://dev.to/thepracticaldev/daily-challenge-7-factorial-decomposition-176o
Daily Challenge 7 - Factorial Decomposition
Today's challenge will require a bit of mathematical prowess. Those who were fans of the Project Euler challenges might have some fun with this one from user g964 from CodeWars:
The aim of this [challenge] is to decompose
n!
(factorial n) into its prime factors. Prime numbers should be in increasing order. When the exponent of a prime number is 1, don't print the exponent.Examples:
n = 22; decomp(22) -> "219 * 39 * 54 * 73 * 112 * 13 * 17 * 19"
n = 25; decomp(25) -> "222 * 310 * 56 * 73 * 112 * 13 * 17 * 19 * 23"Explanation:
n = 12; decomp(12) -> "210 * 35 * 52 * 7 * 11"
12! is divisible by 2 ten times, by 3 five times, by 5 two times and by 7 and 11 only once.
Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Original Link: https://dev.to/thepracticaldev/daily-challenge-7-factorial-decomposition-176o
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To