• python--素数


    import datetime
    start = datetime.datetime.now()
    count = 1
    for x in range(3,100000, 2):
    if x > 10 and x % 10 == 5:
    continue
    for i in range(3,int(x ** 0.5) + 1, 2):
    if x % i == 0:
    break
    else:
    count +=1
    # print(x,count)
    pass
    delta = (datetime.datetime.now() - start).total_seconds()
    print(delta)
    print(count)
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    start = datetime.datetime.now()
    number = 100000
    count = 2
    for num in range(4,number):
    if num%6 !=1 and num%6 !=5:
    continue
    else:
    snum = int(num**0.5+1)
    for i in range(5,snum,2):
    if not num%i:
    break
    else:
    count +=1
    pass
    # print(count)
    delta = (datetime.datetime.now() - start).total_seconds()
    print(delta)
    print(count)
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")




    C:python37python.exe D:/python37/201901/20190109.py
    0.173917
    9592
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    0.168885
    9592
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

     

    我的目标是每天厉害一点点
  • 相关阅读:
    清除所有缓存命令
    web前端工程师面试技巧 常见问题解答
    Web前端开发面试技巧
    JavaScript
    JavaScript Cookie
    JavaScript 计时事件
    javascript 弹窗
    JavaScript Window Navigator
    JavaScript Window History
    JavaScript Window Location
  • 原文地址:https://www.cnblogs.com/sidaofeng/p/10243279.html
Copyright © 2020-2023  润新知