I am writing a program to calculate Prime factors and I need the next prime number to see if my input number is divisible. The list of prime number, up to a large enough number, is known. Example.
My question is, is it good or bad practice to store a list of first 10,000 prime numbers in my C# code and use it while calculating prime factors?
You could possibly store offsets instead:
If your primes are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43
then your offsets would be (with base=2): 0, 1, 1, 2, 2, 3, 2, 4, 2, 4, 6, 2, 6, 4, 2, ...
Basically the offsets are just the difference between a prime and the next prime in the list. Mathematically speaking, I'm not sure if this would really save much space but it might be worth investigating. You could most likely use a smaller datatype to cover the same number space.
Here's an interesting read on the "prime gap" which shows you that the difference in primes stays relatively small throughout very large primes: https://en.wikipedia.org/wiki/Prime_gap
If you're only storing 10,000 primes, this is pointless. Just store them or calculate them.