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)
def IsNumberComposite(n):
if n < 0:
raise ValueError('The value must be positive')
if n in [1, 2]:
return False
if n % 2 == 0:
return True
i = 3
while(i * i <= n):
if n % i == 0:
return True
i += 2
return False
M = int(input())
N = int(input())
for i in range(M, N + 1):
if IsNumberComposite(i):
print(i, end=' ')
print()
Comments
Leave a comment