Earlier I was taking range starting from 2 to half of the value. Now that I am taking from 2 to value. Still, it is showing It’s wrong. Could someone please tell me where I am making mistake?
CodeChef: Practical coding for everyone ///42114122
Earlier I was taking range starting from 2 to half of the value. Now that I am taking from 2 to value. Still, it is showing It’s wrong. Could someone please tell me where I am making mistake?
CodeChef: Practical coding for everyone ///42114122
You have not accounted for the test case where the value of N = 1 which should return false since 1 is not a prime number.
Also, your logic is quite confusing, you can simplify it like my code:
def isPrime(n):
# The case you forgot to add
if n == 1:
return False
for i in range(2, n):
if n % i == 0:
return False;
return True
t = int(input())
for _ in range(t):
n = int(input())
if(isPrime(n)):
print("yes")
else:
print('no')