#K75912. Sum of Divided
Sum of Divided
Sum of Divided
Given a list of positive integers, your task is to find all prime numbers \(p\) such that at least one element in the list is divisible by \(p\). For each such prime, compute the sum of all numbers in the list that are divisible by \(p\). The resulting pairs \((p, \text{sum})\) must be output in increasing order of \(p\).
For example, given the list [12, 15]
, the prime factors are \(2\), \(3\) and \(5\) since:
- 12 is divisible by 2 and 3;
- 15 is divisible by 3 and 5.
The sums are: \(2 \to 12\); \(3 \to 12+15 = 27\); and \(5 \to 15\). Therefore, the output is:
2 12 3 27 5 15
inputFormat
The input is provided as a single line from standard input, containing space-separated positive integers.
Example:
12 15 21 24
outputFormat
For each prime number \(p\) that divides at least one number in the input list, output a line containing two space-separated integers: \(p\) and the sum of all numbers in the list that are divisible by \(p\). The pairs must be printed in increasing order of \(p\).
Example output:
2 36 3 72 5 15 7 21## sample
12 15
2 12
3 27
5 15
</p>