inz
sssms2.c (raw)
/*
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* Version 2, December 2004
*
* Copyright (C) 2021 Santtu Lakkala <inz@inz.fi>
*
* Everyone is permitted to copy and distribute verbatim or modified
* copies of this license document, and changing it is allowed as long
* as the name is changed.
*
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
*
* 0. You just DO WHAT THE FUCK YOU WANT TO.
*
* compile with something like:
* cc -std=c11 sssms2.c -o sssms2 -lm -pthread
*/
#include <stdint.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <inttypes.h>
#include <stdatomic.h>
#include <pthread.h>
static const uint8_t f2[8][8] = {
{ 19, 1, 0, 0, 17, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 136, 0, 0, 0, 136 },
{ 0, 0, 136, 68, 0, 0, 136, 68 },
{ 17, 0, 0, 0, 17, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 136, 0, 0, 0, 136 },
{ 0, 0, 136, 68, 0, 0, 136, 196 }
};
static inline bool issquare(uint64_t x)
{
uint64_t sqr = sqrtl(x);
return sqr * sqr == x;
}
static _Atomic uint64_t ga = ATOMIC_VAR_INIT(1);
static uint64_t high;
void *worker(void *data)
{
uint64_t a;
uint64_t b;
uint64_t c;
(void)data;
while ((a = ga++) < high) {
if ((a & 7) == 5)
continue;
for (b = 1; b <= a; b++) {
const uint8_t f3 = f2[a & 7][b & 7];
if (f3) {
uint64_t a2b2 = a * a + b * b;
uint64_t mrc = sqrtl(a2b2 + b);
uint64_t rc;
for (rc
= sqrt(a2b2
- 1) + 1; rc <= mrc; rc++) {
c = rc * rc - a2b2;
if (f3 & (1 << (c & 7)) &&
issquare(a * a + b + c * c) &&
issquare(a + b * b + c * c))
printf("%" PRIu64
" %" PRIu64
" %" PRIu64
"\n", c
, b
, a
); }
}
}
}
return NULL;
}
int main(int argc, char **argv)
{
int t = 1;
int i;
high = 5000;
if (argc >= 3) {
ga = strtoull(argv[1], NULL, 10);
high = strtoull(argv[2], NULL, 10);
if (argc >= 4)
}
pthread_t threads[t - 1];
for (i = 0; i < t - 1; i++)
pthread_create(&threads[i], NULL, worker, NULL);
worker(NULL);
for (i = 0; i < t - 1; i++)
pthread_join(threads[i], NULL);
return 0;
}