找出自然对数小数点之后的第一个十位的质数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)
作者:百里求一
出处:http://www.cnblogs.com/bergus/
我的语雀: https://www.yuque.com/barry.bai
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。