#C14097. Unique Prime Factors
Unique Prime Factors
Unique Prime Factors
You are given a list of positive integers. Your task is to calculate the unique prime factors from all the given integers and output them in ascending order.
For example, if the input is 28
, then the prime factors of 28 are 2 and 7, so the output should be 2 7
. Similarly, for input 12 15 21
, the unique prime factors are 2, 3, 5, and 7 (since 12 = 2²×3, 15 = 3×5, and 21 = 3×7), so the output is 2 3 5 7
.
Note that the number 1 should be ignored because it does not have any prime factors.
Mathematically, if the prime factorization of a number n is given by
\(n = p_1^{\alpha_1}p_2^{\alpha_2}\cdots p_k^{\alpha_k}\)
then the set of prime factors is \(\{p_1, p_2, \ldots, p_k\}\). Your task is to find the union of such sets for all numbers in the input and output the resulting set in sorted order.
inputFormat
The input consists of a single line containing space-separated positive integers.
outputFormat
Output the unique prime factors found in the input, sorted in ascending order. The output should be a single line with each prime factor separated by a space.
## sample28
2 7