关于python 3.x:为什么这个函数不进入while循环?

Why isn't this function entering the while loop?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def millerRabin(toTest = 3, accuracy = 5):
    # Return true if toTest is prime
    ################################
    # Find how many times toTest can be halved
    print(toTest)
    under = toTest - 1
    loopTracker = 0
    while under % 2 == 0:
        print('Before halving')
        # Keep halving, and keep track until hit we can no longer divide in half
        under = under // 2
        print('After Halving: ', under)
        loopTracker += 1
        print("looped")
    print(loopTracker)

print(millerRabin(toTest = 144000))

Miller-Rabin的第一部分是跟踪待测数量减半的次数。 但是,我无法弄清楚为什么程序没有进入while循环并输出一些打印语句。


当你定义under时,你将减去1.这会创建143999来测试,它不能被2整除。 所以它失败了你的条件,永远不会进入循环。