Quad-power prime seeds: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: Add Ruby) |
(Added C) |
||
Line 135: | Line 135: | ||
77685 79646 80535 82655 85251 86996 91014 96566 97739 105939 |
77685 79646 80535 82655 85251 86996 91014 96566 97739 105939 |
||
108240 108681 119754 122436 123164 126489 140636 150480 153179 163070</pre> |
108240 108681 119754 122436 123164 126489 140636 150480 153179 163070</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; |
|||
bool isQuadPowerPrimeSeed(unsigned int n) { |
|||
int i; |
|||
mpz_set_ui(p, n); |
|||
unsigned int k = n + 1; |
|||
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 count) { |
|||
int m = count % 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 count = 0, m = 1, c = 50; |
|||
mpz_init(p); |
|||
mpz_init(p2); |
|||
setlocale(LC_NUMERIC, ""); |
|||
printf("First fifty quad-power prime seeds:\n"); |
|||
for (n = 1; count < 50; ++n) { |
|||
if (isQuadPowerPrimeSeed(n)) { |
|||
printf("%'7u ", n); |
|||
if (!((++count) % 10)) printf("\n"); |
|||
} |
|||
} |
|||
printf("\nFirst quad-power prime seed greater than:\n"); |
|||
while (1) { |
|||
if (isQuadPowerPrimeSeed(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; |
|||
} |
|||
return 0; |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
First fifty quad-power prime seeds: |
|||
1 2 5 6 69 131 426 1,665 2,129 2,696 |
|||
5,250 7,929 9,689 13,545 14,154 14,286 16,434 19,760 25,739 27,809 |
|||
29,631 36,821 41,819 46,619 48,321 59,030 60,500 61,955 62,321 73,610 |
|||
77,685 79,646 80,535 82,655 85,251 86,996 91,014 96,566 97,739 105,939 |
|||
108,240 108,681 119,754 122,436 123,164 126,489 140,636 150,480 153,179 163,070 |
|||
First quad-power prime seed greater than: |
|||
1 million is the 141st: 1,009,286 |
|||
2 million is the 234th: 2,015,496 |
|||
3 million is the 319th: 3,005,316 |
|||
4 million is the 383rd: 4,004,726 |
|||
5 million is the 452nd: 5,023,880 |
|||
6 million is the 514th: 6,000,554 |
|||
7 million is the 567th: 7,047,129 |
|||
8 million is the 601st: 8,005,710 |
|||
9 million is the 645th: 9,055,151 |
|||
10 million is the 701st: 10,023,600 |
|||
</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |