It's just silly that I can't solve this simple problem...This runs perfectly on Ideone but keeps getting NZEC on SPOJ.I'm using Python 2.7.10
<snip>
Why do you invent your own gcd function? Which test cases did you check?
That question helped me a lot - that gcd was indeed the source of NZEC (entering same a and b returned zero). Thanks!