/* The Liouville function on a integer n is L(n) = (-1)^r where r is the number of prime factors in the prime factorization of n (L(1) = 1). This program is called as sumliouville2 begin end intlen and prints the sum of L(n) for n from 'begin' to 'end'. The sums are computed interval wise, and the length of the intervals is given as 'intlen' (such that one can play with this length, values between 10000 and 100000 seem to be good). Compile with gcc -O2 -Wall -g -o sumliouville2 sumliouville2.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); return 0;
}
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 ist noch experimentell.