Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ program using threads to find number of prime numbers Write a program to fin

ID: 3912902 • Letter: C

Question

C++ program using threads to find number of prime numbers

Write a program to find, and provide a count of prime numbers between 1 and a user provided limit or maximum value. For example, between 1 and 10,000 there are exactly 1229 prime numbers. In order to improve performance, the program should use threads to perform computations in parallel. Additionally, the program should use the C++11 high resolution clock to provide an execution time in milliseconds The program should read the thread count and limit from the command line in the following format: The way to determine if a number is prime is as follows: The numbers 2 and 3 are prime For a given number, i> 3: If i is divisible by 2, then i is not prime If is not divisible by 2, then: Calculate k- the approximate square root of i Try to divide i by all odd numbers 3, 5, 7, etc. less than or equal to k If i is divisible by any of these numbers, then i is not prime To estimate the square root of a number, use the following algorithm: sqrtetnumber number sqrtest +sqrtest sqrtest- Stop iterating when the difference between the current and previous estimates is

Explanation / Answer

#include #include #include #include #include #include #include bool isPrime(int number) { int i; for (i = 2; i tCount; std::stringstream ss1(argv[4]); int lim; ss1 >> lim; limit = lim; auto t1 = std::chrono::high_resolution_clock::now(); std::thread *arr; arr = new std::thread[tCount]; for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote