Cuban primes: Difference between revisions

Content added Content deleted
m (→‎{{header|Maple}}: again, added an incorrect flag for not having the correct output. Please ensure the output for the 1st 200 cuban primes is correct.)
Line 777: Line 777:


{{trans|Go}}
{{trans|Go}}
{{works with|Julia|1.2}}
<lang julia>using Formatting, Primes
<lang julia>using Primes


function cubanprimes(N)
function cubanprimes(N)
cubans = zeros(BigInt, N)
cubans = zeros(Int, N)
cube100k = 0
cube100k, cube1, count = 0, 1, 1
cube1 = BigInt(1)
for i in Iterators.countfrom(1)
count = 1
for i in 1:100000000
j = BigInt(i + 1)
j = BigInt(i + 1)
cube2 = j^3
cube2 = j^3
diff = cube2 - cube1
diff = cube2 - cube1
if isprime(diff)
if isprime(diff)
if count <= N
count ≤ N && (cubans[count] = diff)
cubans[count] = diff
end
if count == 100000
if count == 100000
cube100k = diff
cube100k = diff
Line 802: Line 799:
println("The first $N cuban primes are: ")
println("The first $N cuban primes are: ")
foreach(x -> print(lpad(cubans[x] == 0 ? "" : cubans[x], 10), x % 8 == 0 ? "\n" : ""), 1:N)
foreach(x -> print(lpad(cubans[x] == 0 ? "" : cubans[x], 10), x % 8 == 0 ? "\n" : ""), 1:N)
println("\nThe 100,000th cuban prime is ", format(cube100k, commas=true))
println("\nThe 100,000th cuban prime is ", cube100k)
end
end