Composite Numbers in the range
You are given two integers M, N as input. Write a program to print all the composite numbers present in the given range (including M and N).
Input
The first line of input is an integer M. The second line of input is an integer N.
Explanation
In the given example, the composite numbers present in the range between
2 to 9 are 4, 6, 8, 9.So, the output should be
4
6
8
9
Sample Input 1
2
9
Sample Output 1
4
6
8
9
Sample Input 2
1
4
Sample Output 2
4
m = int(input())
n = int(input())
lst = [0, 0] + [1] * (n - 1)
for i in range(int(n ** 0.5 +1)):
# print('i:', i)
if lst[i]:
for j in range(2, n // i + 1):
# print('j:', j)
lst[j * i] = 0
for i in range(m, n + 1):
if not lst[i]:
print(i)
Comments
Leave a comment