Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1. A prime number, as you know, is a positive integer that has no factors other than 1 and itself. For example, the first

image text in transcribed

Exercise 1. A prime number, as you know, is a positive integer that has no factors other than 1 and itself. For example, the first six prime numbers are 2, 3, 5, 7, 11, and 13. Therefore, if you are asked to find the 6h prime number, the answer is 13. In this exercise, you are to write a program to find the1h, the 101st, 1001st 10001st prime numbers and determine how long your program takes to find each of those primes. Note your results in a table as shown below. Table 1: nth Prime Number il Execution time (millisecs) 101 1001 10001 Using the above table, draw a graph of the evaluation time (y axis) vs input size n. You can use a simple utility like Microsoft Excel to draw the graph or you can also plot it manually and scan it. Notes 1. 2. Use long data type instead of int to fit the large prime numbers. If you use the nave way to determine if a number x is prime (that is, test if every integer less than x is a factor or not), then your program will take a long time to calculate the 10001th prime. There are smarter ways to determine the prime that will reduce the execution time. Source: This question has been adapted from Project Euler (projecteuler.net and programmingbydoing.com)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

2. Discuss the steps in preparing a manager to go overseas.

Answered: 1 week ago

Question

8. Measure the effectiveness of the succession planning process.

Answered: 1 week ago