[SPOJ] WA in POWERUP

Code : http://ideone.com/gEdKdi
Problem : http://www.spoj.com/problems/POWERUP/

def modpow(a,b,c,mod):
if a%mod == 0:
	return 0
	
res = pow(b,c,mod-1)

return pow(a,res,mod) 


while 1:
a,b,c = map(int,raw_input().split())
if a==b and b==c  and c==a and c==-1:
	break
elif a==0 and b==0 and c==0:
	print 1
elif a==0 and b==0 :
	print 1
elif b==0 and c==0:
	print a%1000000007
else:
	print modpow(a,b,c,1000000007)

I am out of ideas now, after 10 WA’s , i can’t see the corner case , any help please ? , Given -> 0^0 = 1

In case anyone wandering the correct solution :
def modpow(a,b,c,mod):
if a%mod == 0:
return 0

res = pow(b,c,mod-1)
if( a==0 and res == 0 ):
	return 1
else:
	return pow(a,res,mod) 


while 1:
	a,b,c = map(int,raw_input().split())
	if a==b and b==c  and c==a and c==-1:
		break
	elif a==0 and b==0 and c==0:
		print 0
	elif a==0 and b==0 :
		print 1
	elif b==0 and c==0:
		print a%1000000007
	else:
		print modpow(a,b,c,1000000007)

elif a==0 and b==0 and c==0:
print 1
it is 0^(0^0) = 0^1 = 0 right my friend?

2 Likes