Jump to content

Prime reciprocal sum: Difference between revisions

m
(J)
Line 61:
11390125639471674628..31060548964273180103 (2358 digits)
</syntaxhighlight>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">""" rosettacode.org/wiki/Prime_reciprocal_sum """
 
using Primes
using ResumableFunctions
 
""" Abbreviate a large string by showing beginning / end and number of chars """
function abbreviate(s; ds = "digits", t = 40, x = (t - 1) ÷ 2)
wid = length(s)
return wid < t ? s : s[begin:begin+x] * ".." * s[end-x:end] * " ($wid $ds)"
end
 
@resumable function generate_oeis75442()
psum = big"0" // big"1"
while true
n = BigInt(ceil(big"1" // (1 - psum)))
while true
n = nextprime(n + 1)
if psum + 1 // n < 1
psum += 1 // n
@yield n
break
end
end
end
end
 
for (i, n) in enumerate(Iterators.take(generate_oeis75442(), 16))
println(lpad(i, 2), ": ", abbreviate(string(n)))
end
</syntaxhighlight>{{out}}
<pre>
1: 2
2: 3
3: 7
4: 43
5: 1811
6: 654149
7: 27082315109
8: 153694141992520880899
9: 337110658273917297268061074384231117039
10: 84241975970641143191..13803869133407474043 (76 digits)
11: 20300753813848234767..91313959045797597991 (150 digits)
12: 20323705381471272842..21649394434192763213 (297 digits)
13: 12748246592672078196..20708715953110886963 (592 digits)
14: 46749025165138838243..65355869250350888941 (1180 digits)
15: 11390125639471674628..31060548964273180103 (2358 digits)
16: 36961763505630520555..02467094377885929191 (4711 digits)
</pre>
 
=={{header|Raku}}==
The sixteenth is very slow to emerge. Didn't bother trying for the seventeenth. OEIS only lists the first fourteen values.
4,107

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.