python 如何判断给定数值 是否存为2的n次方

时间:2014-02-19 05:50:43   收藏:0   阅读:1704
def f(n):
    while True:
        tmp = divmod(n, 2)
        if tmp[1]!=0:
            return False
        if tmp[0]==1:
            return True
        n = tmp[0]

原文:http://www.cnblogs.com/yu-zhang/p/3554511.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!