运行后发现 第一部分求e的后10000位可以得到结果
第二部分就卡住了
我觉得可能是定义或者mod的问题,因为求的是10位数的质数,用tmp(10位数组)除数得到的余数不准确附了代码
求指明方向!!!!拜托了
[Fortran] 纯文本查看 复制代码 Program jiayi
Implicit Real *8(A, C-H, O-S, U-Z)
Integer, Parameter :: nk = 10000
Dimension :: ns(nk), na(nk), nt(nk), prime(20)
Integer :: i, j, b, it, l
Do i = 1, nk
na(i) = 0
ns(i) = 0
nt(i) = 0
End Do
na(1) = 1
ns(1) = 2
n = 1
Do j = 1, 5000
n = n + 1
Do i = 2, nk
nd = mod(na(i-1), n)*10 + nt(i)
nt(i) = nd/n
na(i) = mod(nd, n)
End Do
Do i = 1, nk
na(i) = nt(i)
ns(i) = ns(i) + nt(i)
End Do
Do i = nk, 2, -1
ns(i-1) = ns(i-1) + ns(i)/10
ns(i) = mod(ns(i), 10)
End Do
End Do
Print *, 'e=2.'
Write (*, '(8x,77i1)')(ns(i), i=2, 77)
Write (*, '(80i1)')(ns(i), i=78, nk)
b = 1
loop_utmost: Do i = 2, nk - 10
tmp = 0
If (ns(i)/=0) Then
loop_tmp: Do j = i, i + 9 !loop 10 times to get the 10 digit number, and save it as "tmp"
tmp = tmp*10 + ns(j)
End Do loop_tmp
l = sqrt(tmp+1) !choose the squareroot of the number itself as the biggest divisor to save memory
loop_check: Do it = 2, l !To check whether tmp can be devided by any numbers in the range or not
If (mod(tmp,real(it))==0) Then
Cycle loop_utmost
Else If (it<=l) Then
Cycle loop_check
Else
b = b + 1
If (b<=20) Then
prime(b) = tmp
Cycle loop_utmost
Else
Exit
End If
End If
End Do loop_check
End If
End Do loop_utmost
Print *, 'The ten digital primes in e:'
Write (*, '(i5,f15.1)')(prime(i), i=1, b)
End Program jiayi
|