Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started