PRB01 - Don't get what's wrong here

CodeChef: Practical coding for everyone - link to my solution
It is giving correct output on sample test cases.

try:
    t = int(input())
    if (t>=1 and t<=20):
        while(t!=0):
            n = int(input())
            flag = 1
            if (n>=1 and n<=100000):
                if n>=2:
                    for i in range(2, n//2):
                        if n%i == 0:
                            flag = 0
                            break
                if flag == 1:
                    print("yes")
                else:
                    print("no")
            t-=1
except Exception as e:
    print("Error: ",e)

4 is not prime number your program gives “yes”

this should be (n//2)+1 as for loop iterate < n//2 not < = n//2

also u have to check for n=1 too , your code gives “yes” but answer is no -

" Solution: 45314515 | CodeChef"

Thanks Dude !! It helped. 1 is something i really did not pay attention to. And the loop start and end, that was good catch.

1 Like