# What does Segmentation fault (core dumped) actually mean? [closed]

Block[
{a, primes, tot, $RecursionLimit = Infinity}, primes = Select[Range[10^9, 10^9 + 10^3], PrimeQ]; tot = 0; Do[ a = 1; a[n_] := a[n] = Mod[6 a[n - 1]^2 + 10 a[n - 1] + 3, primes[[i]]]; tot += a[10^5]; Clear[a], {i, Length@primes} ]; tot ] // AbsoluteTiming  I got this error (from linux): Same code in windows, it just stopped and quit from kernel. Does not give any error. • Do you want a unix.stackexchange.com type answer or a Mathematica answer? We call it a kernel crash. If you're using the Front End, you don't see this message when it happens (at least not on a Mac). You hear a beep. – Michael E2 Jul 31 '15 at 20:44 • My first guess is that $RecursionLimit = Infinity let your stack grow too large. (I'm not prepared to crash my Mathematica right now.) – Michael E2 Jul 31 '15 at 20:46
• It's the result of a stack overflow. See stackoverflow.com/questions/2685413 – ilian Jul 31 '15 at 20:46
• @ilian At least it's not the result of stackoverflow.com. ;-) – Michael E2 Jul 31 '15 at 20:48
• @MichaelE2 Yes, they did pick a great name for the site. @Chen Perhaps a non-recursive form like tot += Nest[Mod[6 #^2 + 10 # + 3, primes[[i]]] &, a, 10^5 - 1]; may work better. – ilian Jul 31 '15 at 21:12

As suggested by @ilian , this is now better using a Nest instead of the recursive approach.

Block[
{a, primes, tot},

primes = Select[Range[10^9, 10^9 + 10^3], PrimeQ];
tot = 0;
Do[
tot += Nest[Mod[6 #^2 + 10 # + 3, primes[[i]]] &, 1, 10^(15) - 1];
, {i, Length@primes}
];
tot
] // AbsoluteTiming


Here is an even better version:

Block[ {a, primes},

primes = Select[Range[10^9, 10^9 + 10^3], PrimeQ];

Tr@Table[
Nest[Mod[6 #^2 + 10 # + 3, primes[[i]]] &, 1, 10^(15) - 1],
{i, Length[primes]}
]

] // AbsoluteTiming