0

how to count the number of tree factor?

example input 2 output 2 1 3 1 // from 6=2×3 // there are one 2 and one 3 input 60 output 2 2 3 1 5 1 // from 60=2×2×3×5 //there are two 2, one 3, and one 5

4th Nov 2018, 8:19 AM
Yoaraci
Yoaraci - avatar
1 ответ
+ 1
Get all prime numbers with the Sieve of Eratosthenes, that are below your number divided by 2. Lets take a look at your example with 60: The prims below you are looking for are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29. Take the first prime number: 60 mod 2 == 0 => 2 1 60 / 2 = 30 Repeat with 30: 30 mod 2 == 0 => 2 2 30 / 2 = 15 Repeat with 15: 15 mod 2 != 0 => next prime number 15 mod 3 ==0 => 2 2, 3 1 15 / 3 = 5 Repeat with 5: 5 mod 3 != 0 => next prime number 5 mod 5 ==0 => 2 2, 3 1, 5 1 5 / 5 = 1 => DONE
4th Nov 2018, 9:22 AM
Björn Thomsen
Björn Thomsen - avatar