Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,112 @@
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef long long llong_t;
struct PrimeArray {
llong_t *ptr;
size_t size;
size_t capacity;
};
struct PrimeArray allocate() {
struct PrimeArray primes;
primes.size = 0;
primes.capacity = 10;
primes.ptr = malloc(primes.capacity * sizeof(llong_t));
return primes;
}
void deallocate(struct PrimeArray *primes) {
free(primes->ptr);
primes->ptr = NULL;
}
void push_back(struct PrimeArray *primes, llong_t p) {
if (primes->size >= primes->capacity) {
size_t new_capacity = (3 * primes->capacity) / 2 + 1;
llong_t *temp = realloc(primes->ptr, new_capacity * sizeof(llong_t));
if (NULL == temp) {
fprintf(stderr, "Failed to reallocate the prime array.");
exit(1);
} else {
primes->ptr = temp;
primes->capacity = new_capacity;
}
}
primes->ptr[primes->size++] = p;
}
int main() {
const int cutOff = 200, bigUn = 100000, chunks = 50, little = bigUn / chunks;
struct PrimeArray primes = allocate();
int c = 0;
bool showEach = true;
llong_t u = 0, v = 1, i;
push_back(&primes, 3);
push_back(&primes, 5);
printf("The first %d cuban primes:\n", cutOff);
for (i = 1; i < LLONG_MAX; ++i) {
bool found = false;
llong_t mx = ceil(sqrt(v += (u += 6)));
llong_t j;
for (j = 0; j < primes.size; ++j) {
if (primes.ptr[j] > mx) {
break;
}
if (v % primes.ptr[j] == 0) {
found = true;
break;
}
}
if (!found) {
c += 1;
if (showEach) {
llong_t z;
for (z = primes.ptr[primes.size - 1] + 2; z <= v - 2; z += 2) {
bool fnd = false;
for (j = 0; j < primes.size; ++j) {
if (primes.ptr[j] > mx) {
break;
}
if (z % primes.ptr[j] == 0) {
fnd = true;
break;
}
}
if (!fnd) {
push_back(&primes, z);
}
}
push_back(&primes, v);
printf("%11lld", v);
if (c % 10 == 0) {
printf("\n");
}
if (c == cutOff) {
showEach = false;
printf("\nProgress to the %dth cuban prime: ", bigUn);
}
}
if (c % little == 0) {
printf(".");
if (c == bigUn) {
break;
}
}
}
}
printf("\nThe %dth cuban prime is %lld\n", c, v);
deallocate(&primes);
return 0;
}

View file

@ -0,0 +1,35 @@
#include <gmp.h>
#include <stdio.h>
typedef unsigned long int uint;
int main(void)
{
mpz_t a, b;
mpz_init(a);
mpz_init(b);
int found = 0;
int col = 0;
for (uint n = 1; ; n++) {
mpz_ui_pow_ui(a, n, 3);
mpz_ui_pow_ui(b, n + 1, 3);
mpz_sub(a, b, a);
if (!mpz_probab_prime_p(a, 5)) continue;
if (++found <= 200) {
gmp_printf("%10Zu", a);
if (++col == 8) {
putchar('\n');
col = 0;
}
} else if (found == 100000) {
gmp_printf("100000th: %Zu\n", a);
} else if (found == 1000000) {
gmp_printf("1000000th: %Zu\n", a);
break;
}
}
return 0;
}