下面代码用于统计 n 中因子 2 出现了多少次。若 n = 40,输出是
n = 40 cnt = 0 while n % 2 == 0: cnt += 1 n = n // 2 print(cnt)
1
2
3
4