Hide

Problem BN
Prime Reduction

A prime number p2 is an integer which is evenly divisible by only two integers: 1 and p. A composite integer is one which is not prime. The fundamental theorem of arithmetic says that any integer x can be expressed uniquely as a set of prime factors – those prime numbers which, when multiplied together, give x. Consider the prime factorization of the following numbers:

10=2×516=2×2×2×2231=3×7×11

Consider the following process, which we’ll call prime reduction. Given an input x:

  1. if x is prime, print x and stop

  2. factor x into its prime factors p1,p2,,pk

  3. let x=p1+p2++pk

  4. go back to step 1

Write a program that implements prime reduction.

Input

Input consists of a sequence of up to 20000 integers, one per line, in the range 2 to 109. The number 4 will not be included in the sequence (try it to see why it’s excluded). Input ends with a line containing only the number 4.

Output

For each integer, print the value produced by prime reduction executed on that input, followed by the number of times the first line of the process executed.

Sample Input 1 Sample Output 1
2
3
5
76
100
2001
4
2 1
3 1
5 1
23 2
5 5
5 6
Hide

Please log in to submit a solution to this problem

Log in