Question: Write an algorithm to find all prime numbers up to some limit N. For this algorithm, consider every number from 2 up to N.
Write an algorithm to find all prime numbers up to some limit N. For this algorithm, consider every number from 2 up to N. If it is a prime, you include it in the list. To test whether a number m is a prime number you simply divide it by each of the numbers 2, 3...m-1; if any of these divisions is without remainder, then m is not prime, otherwise it is. Your program should take two command line arguments (the algorithm number and N) and output the primes using System.out.println and the timing data using System.err.println - so you could run your program like this: java -jar Primes.jar 1 17 and get an output like this: 2 3 5 7 11 13 17 1 The first 7 numbers are prime numbers less than/equal to 17, the last number is the time taken to run the algorithm. Write an algorithm to find all prime numbers up to some limit N. For this algorithm, consider every number from 2 up to N. If it is a prime, you include it in the list. To test whether a number m is a prime number you simply divide it by each of the numbers 2, 3...m-1; if any of these divisions is without remainder, then m is not prime, otherwise it is. Your program should take two command line arguments (the algorithm number and N) and output the primes using System.out.println and the timing data using System.err.println - so you could run your program like this: java -jar Primes.jar 1 17 and get an output like this: 2 3 5 7 11 13 17 1 The first 7 numbers are prime numbers less than/equal to 17, the last number is the time taken to run the algorithm.
Step by Step Solution
3.39 Rating (152 Votes )
There are 3 Steps involved in it
The image contains instructions for writing an algorithm to find all prime numbers up to s... View full answer
Get step-by-step solutions from verified subject matter experts
