Thursday, November 16, 2017

Product of three consecutive primes

A number N is the product of three consecutive prime numbers. N is passed as input to the program. The program must print the three consecutive prime numbers in ascending order. The prime numbers must be separated by a single space.

Input Format:
The first line will contain the value of N.

Boundary Conditions: 30 <= N <= 99999999

Output Format:
The three consecutive prime numbers when multiplied gives N (separated by a single space)

Example Input/Output 1:
Input:
30
Output:
2 3 5
Explanation: 30 = 2*3*5. Hence 2 3 5 is printed as output.

Solution:
s=int(input())
for i in range(2,int(s**(0.5))):
    if s%i==0:
        print(i,end=' ')
Share: