我刚刚遇到了声称被谷歌 2004 年使用的挑战之一
(the first 10-digit prime in e).com
Run Code Online (Sandbox Code Playgroud)
除此之外,我想接受挑战并用 python 解决它
>>> '%0.52f' % math.exp(1)
'2.71828182845904509079**5598298427**6488423347473144531250'
>>> '%0.52f' % numpy.exp(1)
'2.71828182845904509079**5598298427**6488423347473144531250'
Run Code Online (Sandbox Code Playgroud)
我的程序返回的5598298427是一个素数
上网查了一下,正确答案是7427466391
但是 python 中的 exp 数字不包括上面的数字
import numpy
import math
def prime(a):
if a == 2: return True
if a % 2 == 0: return False
if a < 2: return False
i = 2
n = math.sqrt(a) + 1
while(i < n):
if a % i == 0:
return False
i += 1 …Run Code Online (Sandbox Code Playgroud) #include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a = sqrt(2);
cout << a << endl;
}
Run Code Online (Sandbox Code Playgroud)
嗨这是找到sqrt为2的程序,它在输出中只打印1.41421如何实现它的方式使得它将在小数点后打印200000位数
1.41421 ..........高达200 000位
有这样的印刷方法吗?
我试图建立一个恒定的随机数生成器(我的意思是一个RNG输出一系列不重复的数字,但每次从头开始都保持不变).我有一个pi.我需要一种算法来逐位生成e以馈入RNG,最好是以Python迭代器或生成器的形式.我也欢迎产生其他无理数的代码.提前致谢.