N Numbers Divisible by X or Y
Coding Problem Keys
N Numbers Divisible by X or Y
Problem Statement
The three integers X, Y and N are passed as input. The program must print the first N values from 1 which are divisible by X or Y.Boundary Condition(s)
1 <= X, Y, N <= 999Input Format
The first line contains the value of X.The second line contains the value of Y.
The third line contains the value of N.
Output Format
The first line contains N integers separated by space.Example Input/Output 1
Input
37
10
Output
3 6 7 9 12 14 15 18 21 24
Explanation
The numbers divisible by 3 or 7 for 10 numbers is 3, 6, 7, 9, 12, 14, 15, 18, 21, 24.
Example Input/Output 2
Input
45
8
Output
4 5 8 10 12 15 16 20Explanation
The numbers divisible by 4 or 5 for 8 numbers is 4, 5, 8, 10, 12, 15, 16, 20.
Max Execution Time Limit: 5000 millisecs
Solution
Programming Language: Python 3 Language
x=int(input())
y=int(input())
n=int(input())
l=[]
for i in range(x,(x+y)*n):
if(i%x==0 or i%y==0) and len(l)<n:
l.append(i)
else: pass
print(*l)
# Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments