Question: 1 Problem 1 Create a program that generates a file of all the prime numbers less than a number N taken from command line. It

1 Problem 1 Create a program that generates a file of all the prime numbers less than a number N taken from command line. It is up to you how you store this data into the file as long as your next problem can read it. Your program should work for numbers up to 100,000. You must implement the Sieve of Eratosthenes in order to generate this file. You are welcome to take a look at the wikipedia source on this which even includes some pseudocode https://en.wikipedia.org/ wiki/Sieve_of_Eratosthenes

Example input: 10

Example output in file.txt:

2 3 5 7 2

Problem 2 Create a program that takes a file of prime numbers generated from Problem 1 and stores them in any way of your choosing. The user may query the program as many times as they would like and it will output whether or not the number given is prime. The queries must run in log(n) time where n is the amount of prime numbers in the file. If the number that is entered is negative stop the program. If the number is greater than the largest in the file inform the user that they need a file which contains more prime numbers.

Example input in file.txt: 2 3 5 7

Example command line interaction with user: Enter a number. 3 3 is a prime number. Enter another number.

4

4 is not a prime number. Enter another number. 8

Current file not large enough for 8.

Enter another number. -1

Bye.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!