program to print the first prime numbers in the given input
Sample Input 2
4
2
3
5
7
Sample Output 2
2
Sample Input 1
5
1
10
4
3
2
Sample Output 1
3
can i get coode for this the above code is not working for both cases
def is_prime(x):
if x < 2:
return False
if x == 2:
return True
if x % 2 == 0:
return False
p = 3
while p*p <= x:
if x % p == 0:
return False
p += 2
return True
def main():
n = int(input())
pn = None
for i in range(n):
x = int(input())
if pn is None:
if is_prime(x):
pn = x
if pn is not None:
print(pn)
main()
Comments
Leave a comment