I have this assignment in school; we are to write a simple program/method/algorithm in java that has us take two numerical inputs and output count of all the numbers in the range between two inputs which are dividable by 2 or 3 or 5.
The assignment is fairly simple, since you can just iterate through all the numbers in range and increment the counter whenever all the criteria is met.
But we also get 10 test inputs and a timer that evaluates the efficiency of our algorithm. First eight fell through, since the eight values were < 10^6. But the last two test input vales were < 10^18 and my algorithm failed.
So I started thinking in the direction of prime number counting function and sieve Eratosthenes, but my head started to hurt. Any ideas on a faster but still simple enough algorithm?