Penta-power prime seeds: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: Add Ruby) |
(Added C) |
||
Line 142: | Line 142: | ||
414099 628859 644399 770531 781109 782781 |
414099 628859 644399 770531 781109 782781 |
||
923405 1121189 1158975 1483691 1490475 1512321</pre> |
923405 1121189 1158975 1483691 1490475 1512321</pre> |
||
=={{header|C}}== |
|||
{{trans|Wren}} |
|||
{{libheader|GMP}} |
|||
<syntaxhighlight lang="c">#include <stdio.h> |
|||
#include <stdbool.h> |
|||
#include <locale.h> |
|||
#include <gmp.h> |
|||
mpz_t p, p2, q; |
|||
bool isPentaPowerPrimeSeed(unsigned int n) { |
|||
int i; |
|||
mpz_set_ui(p, n); |
|||
unsigned int k = n + 1; |
|||
mpz_add_ui(p2, q, k); |
|||
if (!mpz_probab_prime_p(p2, 15)) return false; |
|||
mpz_add_ui(p2, p, k); |
|||
if (!mpz_probab_prime_p(p2, 15)) return false; |
|||
for (i = 0; i < 3; ++i) { |
|||
mpz_mul_ui(p, p, n); |
|||
mpz_set(p2, p); |
|||
mpz_add_ui(p2, p2, k); |
|||
if (!mpz_probab_prime_p(p2, 15)) return false; |
|||
} |
|||
return true; |
|||
} |
|||
const char *ord(int c) { |
|||
int m = c % 100; |
|||
if (m >= 4 && m <= 20) return "th"; |
|||
m %= 10; |
|||
return (m == 1) ? "st" : |
|||
(m == 2) ? "nd" : |
|||
(m == 3) ? "rd" : "th"; |
|||
} |
|||
int main() { |
|||
unsigned int n; |
|||
int c = 0, m = 1; |
|||
mpz_init(p); |
|||
mpz_init(p2); |
|||
mpz_init_set_ui(q, 1); |
|||
setlocale(LC_NUMERIC, ""); |
|||
printf("First fifty penta-power prime seeds:\n"); |
|||
for (n = 1; c < 30; n += 2) { |
|||
if (isPentaPowerPrimeSeed(n)) { |
|||
printf("%'9u ", n); |
|||
if (!((++c) % 10)) printf("\n"); |
|||
} |
|||
} |
|||
n = 1; |
|||
c = 0; |
|||
printf("\nFirst penta-power prime seed greater than:\n"); |
|||
while (1) { |
|||
if (isPentaPowerPrimeSeed(n)) { |
|||
++c; |
|||
if (n > 1000000 * m) { |
|||
printf(" %2d million is the %d%s: %'10u\n", m, c, ord(c), n); |
|||
if (++m == 11) break; |
|||
} |
|||
} |
|||
n += 2; |
|||
} |
|||
return 0; |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
First fifty penta-power prime seeds: |
|||
1 5 69 1,665 2,129 25,739 29,631 62,321 77,685 80,535 |
|||
82,655 126,489 207,285 211,091 234,359 256,719 366,675 407,945 414,099 628,859 |
|||
644,399 770,531 781,109 782,781 923,405 1,121,189 1,158,975 1,483,691 1,490,475 1,512,321 |
|||
First penta-power prime seed greater than: |
|||
1 million is the 26th: 1,121,189 |
|||
2 million is the 39th: 2,066,079 |
|||
3 million is the 47th: 3,127,011 |
|||
4 million is the 51st: 4,059,525 |
|||
5 million is the 59th: 5,279,175 |
|||
6 million is the 63rd: 6,320,601 |
|||
7 million is the 68th: 7,291,361 |
|||
8 million is the 69th: 8,334,915 |
|||
9 million is the 71st: 9,100,671 |
|||
10 million is the 72nd: 10,347,035 |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |