Smallest number k such that k+2^m is composite for all m less than k: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Promote. multiple implementations, no questions) |
(Added Go) |
||
Line 26: | Line 26: | ||
[[oeis:A033919|OEIS:A033939 - Odd k for which k+2^m is composite for all m < k]] |
[[oeis:A033919|OEIS:A033939 - Odd k for which k+2^m is composite for all m < k]] |
||
=={{header|Go}}== |
|||
{{trans|Wren}} |
|||
{{libheader|GMP(Go wrapper)}} |
|||
Takes around 2.2 seconds though faster than using Go's native big.Int type which takes 6.2 seconds. |
|||
<lang go>package main |
|||
import ( |
|||
"fmt" |
|||
big "github.com/ncw/gmp" |
|||
) |
|||
// returns true if k is a sequence member, false otherwise |
|||
func a(k int64) bool { |
|||
if k == 1 { |
|||
return false |
|||
} |
|||
bk := big.NewInt(k) |
|||
for m := uint(1); m < uint(k); m++ { |
|||
n := big.NewInt(1) |
|||
n.Lsh(n, m) |
|||
n.Add(n, bk) |
|||
if n.ProbablyPrime(15) { |
|||
return false |
|||
} |
|||
} |
|||
return true |
|||
} |
|||
func main() { |
|||
count := 0 |
|||
k := int64(1) |
|||
for count < 5 { |
|||
if a(k) { |
|||
fmt.Printf("%d ", k) |
|||
count++ |
|||
} |
|||
k += 2 |
|||
} |
|||
fmt.Println() |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
773 2131 2491 4471 5101 |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Line 37: | Line 83: | ||
println(take(5, A033939)) # List: (773 2131 2491 4471 5101) |
println(take(5, A033939)) # List: (773 2131 2491 4471 5101) |
||
</lang> |
</lang> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |