I have a large number of modulo calculations to perform. The basic calculation is as follows:
const uint64_t start; // Some "large" number that does NOT change
uint32_t prime[bigNumber]; // Precalculated sequential prime numbers (generated on the fly from a bit compaction storage method for space reasons).
uint64_t answer[bigNumber]; // The "modulo" answers
for (uint64_t i = 0; i < bigNumber; i++) {
uint32_t factor = prime[i];
answer[i] = (factor - 1) - ((start - 1) % factor);
}
Note: start is generally much larger than prime[i].
Is there a faster way to calculate the "answer(s)" without performing a modulo / division for each iteration (AKA can knowing answer[i - 1] help you get answer[i] faster)? Any other improvements or suggestions would greatly be appreciated.