After reading up a bit, the general equation for cuban primes is prime numbers of the form ((x+k)3 - x3)/k where k mod 3 is not equal 0.
The cubans where k == 1 (the focus of this task) is one of many possible groups. In general, it seems like the cubans where k == 1 and k == 2 are the two primary cases, but it is possible to have cubans with a k of any integer that is not a multiple of 3.
Here are the first 20 for each valid k up to 10:
subcomma { $^i.flip.comb(3).join(',').flip }for 2..10 -> \k {nextif k %% 3;my @cubans = lazy (1..Inf).map({ (($_+k)³ - .³)/k }).grep: *.is-prime; put "First 20 cuban primes where k = {k}:"; put @cubans[^20]».&comma».fmt("%7s").rotor(10).join: "\n"; put '';}
Output:
First 20 cuban primes where k = 2:
13 109 193 433 769 1,201 1,453 2,029 3,469 3,889
4,801 10,093 12,289 13,873 18,253 20,173 21,169 22,189 28,813 37,633
First 20 cuban primes where k = 4:
31 79 151 367 1,087 1,327 1,879 2,887 3,271 4,111
4,567 6,079 7,207 8,431 15,991 16,879 17,791 19,687 23,767 24,847
First 20 cuban primes where k = 5:
43 67 97 223 277 337 727 823 1,033 1,663
2,113 2,617 2,797 3,373 4,003 5,683 6,217 7,963 10,273 10,627
First 20 cuban primes where k = 7:
73 103 139 181 229 283 409 643 733 829
1,039 1,153 1,399 1,531 1,669 2,281 2,803 3,181 3,583 3,793
First 20 cuban primes where k = 8:
163 379 523 691 883 2,203 2,539 3,691 5,059 5,563
6,091 7,219 8,443 9,091 10,459 11,923 15,139 19,699 24,859 27,091
First 20 cuban primes where k = 10:
457 613 997 1,753 2,053 2,377 4,357 6,373 9,433 13,093
16,453 21,193 27,673 28,837 31,237 37,657 46,153 47,653 49,177 62,233
k == 2^128
Note that Raku has native support for arbitrarily large integers and does not need to generate primes to test for primality. Using k of 2^128; finishes in well under a second.
subcomma { $^i.flip.comb(3).join(',').flip }my \k = 2**128;put "First 10 cuban primes where k = {k}:";.&comma.put for (lazy (0..Inf).map({ (($_+k)³ - .³)/k }).grep: *.is-prime)[^10];
Output:
First 10 cuban primes where k = 340282366920938463463374607431768211456:
115,792,089,237,316,195,423,570,985,008,687,908,160,544,961,995,247,996,546,884,854,518,799,824,856,507
115,792,089,237,316,195,423,570,985,008,687,908,174,836,821,405,927,412,012,346,588,030,934,089,763,531
115,792,089,237,316,195,423,570,985,008,687,908,219,754,093,839,491,289,189,512,036,211,927,493,764,691
115,792,089,237,316,195,423,570,985,008,687,908,383,089,629,961,541,751,651,931,847,779,176,235,685,011
115,792,089,237,316,195,423,570,985,008,687,908,491,299,422,642,400,183,033,284,972,942,478,527,291,811
115,792,089,237,316,195,423,570,985,008,687,908,771,011,528,251,411,600,000,178,900,251,391,998,361,371
115,792,089,237,316,195,423,570,985,008,687,908,875,137,932,529,218,769,819,971,530,125,513,071,648,307
115,792,089,237,316,195,423,570,985,008,687,908,956,805,700,590,244,001,051,181,435,909,137,442,897,427
115,792,089,237,316,195,423,570,985,008,687,909,028,264,997,643,641,078,378,490,103,469,808,767,771,907
115,792,089,237,316,195,423,570,985,008,687,909,158,933,426,541,281,448,348,425,952,723,607,761,904,131