This versions will give correct answers for n less than 341550071728321 and then reverting to the probabilistic form of the first solution. By selecting predetermined values for the a values to use instead of random values, the results can be shown to be deterministically correct below certain thresholds.
For 341550071728321 and beyond, I have followed the pattern in choosing a from the set of prime numbers.
While this uses the best sets known in 1993, there are better sets known , and at most 7 are needed for 64-bit numbers.
I have an RV setup of 2, 12V battery banks. The first consist of 2, 12V car batteries in parallel supplying a 1000w inverter. The second is 2 deep cycle marine 12V batteries in parallel supplying a 2000w inverter. I use two 100w solar panels to keep both banks charged. I recently purchased a Schumacher SE-1250 charger to start providing equalizer charges to the batteries. I have generated a tracker for measuring each cell temp and SG during the normal charging phase (10A) and for the EQ phase (30A). Each bank took about 12 hours to complete, 6 hours per battery. 5 hours at 10A and 1hour at 30A with readings every 30 mins for each cell. My plan is to do this quarterly to generate sufficient data to determine if I need to increase or decrease the EQ phase.