This is a pretty simple code and works fine in ideone also . But it is giving Runtime Error in SPOJ.
from fractions import gcd
flag=0
while True:
if flag==1:
break
try:
m=map(int,raw_input("").strip().split())
if len(m)!=1:
continue
flag=1
koi=m[0]
while koi:
b0=map(int,raw_input("").strip().split())
if len(b0)!=1:
continue
b=b0[0]
koi-=1
i=1
s=0
while i<=b-2:
if gcd(i,i+1)==1 and gcd(i,i+2)==1 and gcd(i+1,i+2)==1:
s+=i%b
i+=1
print s%b
except(EOFError):
break
Moreover I saw there is successful submission in Python by Francky So there should be no problem as such with the test cases. Please help me in getting rid of this NZEC error.
Thanks a Lot