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.
Boundary Condition(s):
1 <= N <= 10^4
1 <= K <= 100
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.
Example Input/Output 1:
Input:
100 5
Output:
10 20 25 50 100
Example Input/Output 2:
Input:
24 10
Output:
1 2 3 4 6 8 12 24
N,K=map(int,input().split())
arr=[]
for index in range(1,N+1):
if N%index==0:
arr.append(index)
print(*arr[-K:])
Leave a Reply