Prime numbers whose neighboring pairs are tetraprimes: Difference between revisions
Prime numbers whose neighboring pairs are tetraprimes (view source)
Revision as of 17:12, 27 June 2023
, 11 months ago→{{header|C}}: Updated in line with Wren example of which it is a translation - about 5 times quicker than before.
(→{{header|Wren}}: Rewritten to improve performance - more than 5 times quicker than before.) |
(→{{header|C}}: Updated in line with Wren example of which it is a translation - about 5 times quicker than before.) |
||
Line 174:
=={{header|C}}==
{{trans|Wren}}
{{libheader|primesieve}}
{{libheader|GLib}}
<syntaxhighlight lang="c">/* gcc -O3 `pkg-config --cflags glib-2.0` tetraprime.c -o tp `pkg-config --libs glib-2.0` -lprimesieve */▼
▲<syntaxhighlight lang="c">/* gcc `pkg-config --cflags glib-2.0` tetraprime.c -o tp `pkg-config --libs glib-2.0` -lprimesieve */
#include <stdio.h>
Line 188:
#define TEN_MILLION 10000000
size_t size;
int* primes;
void init() {
primes = (int*) primesieve_generate_primes(2, TEN_MILLION, &size, INT_PRIMES);
}▼
n /= 2;▼
bool isTetraPrime(int n) {
int p, count =
for (i = 0;
p = primes[i];
▲ n /= 5;
} else {
▲ i = (i + 1) % 8;
}
}
if (n > 1) {
}
▲}
int i;▼
▲ if (length == 1) return false;
int i;▼
}
Line 252 ⟶ 234:
int main() {
int i, p, c, k, length, sevens, min, max, med;
int j = 100000, sevens1 = 0, sevens2 = 0;
int
const char *t;
GArray *tetras1 = g_array_new(FALSE, FALSE, sizeof(int));
GArray *tetras2 = g_array_new(FALSE, FALSE, sizeof(int));
GArray *tetras;
setlocale(LC_NUMERIC, "");
p =
if (p < j) {
// process even numbers first as likely to have most factors
if (cond1 && cond2) {▼
g_array_append_val(tetras1, p);
if (
}
if (isTetraPrime(p+1) && isTetraPrime(p+2)) {
▲ if (cond3 && cond4) {
g_array_append_val(tetras2, p);
if (
}
} else {
Line 317 ⟶ 286:
printf("\n");
free(gaps);
}
j *= 10;
}
Line 323 ⟶ 293:
g_array_free(tetras1, FALSE);
g_array_free(tetras2, FALSE);
primesieve_free(primes);
return 0;
}</syntaxhighlight>
|