/* The Liouville function on a integer n is L(n) = (-1)^r where r is thenumberofprimefactorsintheprimefactorizationofn(L(1)=1). Thisprogramiscalledas sumliouville2beginendintlen andprintsthesumofL(n)fornfrom'begin'to'end'.Thesumsare computedintervalwise,andthelengthoftheintervalsisgivenas 'intlen'(suchthatonecanplaywiththislength,valuesbetween 10000and100000seemtobegood). Compilewith gcc-O2-Wall-g-osumliouville2sumliouville2.c-lm
*/ #include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <math.h>
long begin, end, intlen, len, l; char *res; long * found;
end = beginall + intlen - 1; if (end > endall) end = endall; for (begin = beginall, res = resall; end <= endall;
begin += intlen, res += intlen) {
len = end - begin + 1; for(i=1; i<=len; i++) found[i] = 1; /* mark parity of number of prime factors */
do_p(2); for (i = 1; i <= n2; i++) { if (erat[i] == 0) {do_p(2*i + 1); }
} /* adjust if one more prime */
off = begin-1; for (i=1; i<=len; i++) if (found[i] < off+i) res[i] = -res[i];
/* end of next intervall */ if (end == endall)
end += 1; else {
end += intlen; if (end > endall) end = endall;
}
}
/* compute sum */
sum = 0; for (i=1; i<=l; i++) {
sum += resall[i];
}
printf("%ld\n", sum); return0;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.8 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.