I am using Mathematica to perform trial divisions on large Mersenne numbers using specific prime numbers (e.g., primes of the form 8n+1 or 8n-1) and would like the program to abort once a factor is found. Here is an example of the code I have so far:
For[n = 1, n < 2^30, n++, If[PrimeQ[8 n - 1], If[Divisible[2^115770329- 1, 8 n - 1], Print["Factor at n = ", n]; Abort]]]
This is fine for just testing one form of prime numbers, however, I would like to test both forms at the same time in parallel and have both abort if one finds a factor. I can open two notebooks and have two separate sets of code running at the same time, window / kernel 1 running for 8n-1 and window / kernel 2 running for 8n+1 however if kernel 1 finds a factor and aborts, kernel 2 will needlessly continue running until it also finds a factor or reaches "n max". I would like both to run at the same time and both to abort if one finds a factor and then print the "n" that caused both to abort.
Thank you for any help or advice!