0
$\begingroup$
Block[
    {a, primes, tot, $RecursionLimit = Infinity},
    primes = Select[Range[10^9, 10^9 + 10^3], PrimeQ];
    tot = 0;
    Do[
        a[1] = 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):

enter image description here

Same code in windows, it just stopped and quit from kernel. Does not give any error.

$\endgroup$

closed as off-topic by Arnoud Buzing, m_goldberg, MarcoB, C. E., Michael E2 Aug 1 '15 at 13:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, C. E.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ 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. $\endgroup$ – Michael E2 Jul 31 '15 at 20:44
  • 1
    $\begingroup$ My first guess is that $RecursionLimit = Infinity let your stack grow too large. (I'm not prepared to crash my Mathematica right now.) $\endgroup$ – Michael E2 Jul 31 '15 at 20:46
  • 1
    $\begingroup$ It's the result of a stack overflow. See stackoverflow.com/questions/2685413 $\endgroup$ – ilian Jul 31 '15 at 20:46
  • 2
    $\begingroup$ @ilian At least it's not the result of stackoverflow.com. ;-) $\endgroup$ – Michael E2 Jul 31 '15 at 20:48
  • 1
    $\begingroup$ @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[1], 10^5 - 1]; may work better. $\endgroup$ – ilian Jul 31 '15 at 21:12
2
$\begingroup$

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
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.