Jump to content

Curzon numbers: Difference between revisions

→‎{{header|Ruby}}: Switched to modular pow like Python
(Python: much faster with modpow)
(→‎{{header|Ruby}}: Switched to modular pow like Python)
Line 1,356:
<syntaxhighlight lang="ruby">def curzons(k)
Enumerator.new do |y|
(1..).each {do |n| y << n if (k ** n + 1) % (k * n + 1) == 0 }
m = k * n + 1
y << n if k.pow(n, m ) + 1 == m
end
end
end
 
[2,4,6,8,10].each do |base|
puts "Curzon numbers with k = #{base}:"
puts curzons(base).take(50).join(", ")
puts "Thousandth Curzon with k = #{base}: #{curzons(base).find.each.with_index(1){|_,i| i == 1000} }",""
end</syntaxhighlight>
 
Line 1,386 ⟶ 1,389:
Thousandth Curzon with k = 10: 46845.
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">fn modpow(mut base: usize, mut exp: usize, n: usize) -> usize {
1,149

edits

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