Last K Factors of N
Coding Problem Keys
Last K Factors of N
Problem Statement
The program must accept two integers N and K as the input. The program must print the last K factors of N in ascending order as the output. If the number of factors in N is less than K, the program must print all the factors of N in ascending order.
Input Format
The first line contains N and K separated by a space.
Output Format
The first line contains the integer value(s) separated by a space.Boundary Condition(s)
1 <= N < 10⁴1 <= K <= 100
Example Input/Output 1
Input
100 5
Output
10 20 25 50 100
Example Input/Output 2
Input
24 10Output
1 2 3 4 6 8 12 24
Max Execution Time Limit: 500 millisecs
Solution
Programming Language: Python 3 Language
n,k=map(int,input().split())
c=[n]
for i in range(n//2,0,-1):
if(n%i==0):
c.append(i)
print(*sorted(set(c[:k])))
# Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments