找出自然对数小数点之后的第一个十位的质数python求解

# -*- coding: utf-8 -*-
from decimal import *


def gen_e_10():
    i = 100
    while 1:
        getcontext().prec = i
        _q = str(Decimal(1).exp())
        print _q
        yield _q
        i *= 2


def isPrime(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    i = 3
    while i * i <= n:
        if n % i == 0:
            return False
        i += 2
    return True


def get_10(n):
    i = 10
    while 1:
        if len(n) > 10:
            m = n[:10]
            n = n[1:]
            yield m
        else:
            break


def main():
    for i in gen_e_10():
        i = i[2:]
        for j in get_10(i):
            if not j:
                break

            print j
            if isPrime(int(j)):
                print "\n\n", j, "\n\n"
                return


if __name__ == '__main__':
    main()
    # print isPrime(7427466391)
posted @ 2017-05-27 12:54  白云辉  阅读(323)  评论(0编辑  收藏  举报