This Batch program contains algorithms for calculating Prime Numbers. So, I’ve made two batch files for calculations – but, the algorithm by which they are calculating prime numbers is slightly different. Due to this reason, one is calculating them faster than other.
Two different Algorithms – Same OUTPUT!
Concept: This Batch file is simply working blindly on the same fact that a prime number has only two divisors, repeating the second nested FOR LOOP until the number is achieved itself. So, it makes the loop slower as the number (which we have to check is prime or not) gets bigger and bigger. That’s why I called this the slower algorithm.
Concept: This Batch file is based on the fact that if a number is not divisible by any of the basic numbers (i.e. 1 to 13). Then it can be considered as prime numbers.
Because all other numbers can be factorized by these basic numbers, I’m not so sure about the accuracy in all cases of this algorithm , but it worked fine when tested it 12 to 15 times.
Update: I’ve Again Checked the Faster Algorithm – And, Luckily Found Some Flaws. Using the slower algorithm gives the correct answer with all integers.
Look at the Difference in the OUTPUT of PRIME NUMBERS UPTO 1000 – with both the Algorithms.