spoj problem link nzec error in python


my solution is givingruntime nzec error for this code
t = int(raw_input())
while t:
s = raw_input().split()
n = int(s[0])
k = int(s[1])
m = int(s[2])
cnt =0
if n greater than and equal to m:
print β€œ0”
continue
d = 0
while 1:
if n less than and equal to m:
n = (n * k)
cnt = cnt + 1
else:
break
                print cnt - 1
        
                t= t-1
    
    but for the same problem another code which is not much different than me is getting accepted
    the accepeted code is
    tc=int(raw_input())
    while(tc):
    	s=raw_input().split()
    	n=int(s[0])
    	k=int(s[1])
    	m=int(s[2])
    
    	d=0
    	while(1):
    		n=n*k
    		d=d+1
    		if(n greater than m):
    			d=d-1
    			break
    	print d
    	tc-=1

i am completely unable to figure where i am getting wrong
need urgent help

in the code when n >= m you β€œcontinue” the loop without even decrementing the no. of test cases left, i.e, the variable t. So input file and you input format mismatches when such test case occurs.

Suggestions:

  1. use β€œfor _ in xrange(int(raw _ input))”, saves time and looks more pythonic
  2. use map(int, raw_input().split()) to obtain an array from the input consisting of space separated integers, again saves time and more pythonic

thanx yaar my code accepted

1 Like