python 函数代码 运算出错

def qiuni(a_num,b_to_mod):
a_tmp=a_num;
for i in range(1,b_to_mod):
if (a_tmp*a_num)%b_to_mod==1:
return i+1
else:
a_tmp=(a_tmp*a_num)%b_to_mod

运行qiuni(23,83)的时候结果为0了,其他数如(3,7)(3,11)都正常,百思不得其解
而且调试时发现是算到某一步突然a_tmp变成零了,和我计算器算循环下一步的值不符
这个是求模逆的函数。。。比如a的x次方mod b=1 求x

为什么我算不是等于0呢

Python 2.7.3 |EPD_free 7.3-2 (32-bit)| (default, Apr 12 2012, 14:30:37) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> def qiuni(a_num,b_to_mod):
    a_tmp=a_num;
    for i in range(1,b_to_mod):
        if (a_tmp*a_num)%b_to_mod==1:
            return i+1
       销碧档 else:
            a_tmp=(a_tmp*a_num)%b_to_mod
    亏乱       慧雀    
>>> qiuni(28,83)
41
>>> qiuni(23,83)
41