Determine the value of the function pn for different value

Assignment Help C/C++ Programming
Reference no: EM132103239

Prime Sum C program !! Dynamically allocated memory

Let P(n) denote the sum of the first n prime numbers. For example, P(1) = 2 and P(3) = 10, since the first three prime numbers are 2, 3 and 5, respectively.

Write a program to determine the value of the function P(n) for different values of n. The first few prime sums are 2, 5, 10, 17, 28, 41, 58 and 77. Input The first line of the input file contains a single positive integer, t (t = 20000), representing the number of test cases.

The following t lines contain one positive integer n (n = 10000), representing the prime sum to be computed for the case. Output Write out a single integer on a line by itself for each test case, indicating P(n), for the corresponding input value n.
Sample Input
3
1
6
8
Sample Output
2
41
77

Assignment Details

Even though this assignment can be coded with statically allocated arrays, please write your solution using dynamically allocated arrays.
(Your programs should have either malloc/calloc calls, as well as a call to free.)

In order to efficiently generate the first 10000 primes, please use the Sieve of Eratosthenes. From there, just generate each of the prime sums instead of recomputing for each test case.

Reference no: EM132103239

Questions Cloud

Identify and classify the information contained : Based on the potential for misuse or embarrassment, what information would be confidential, sensitive but unclassified, or for public release?
Write ruby function prime : (2) Using prime? (n) write Ruby function primearray(n) that returns an array that contains all prime numbers that are less than n.
What tactics she can use to get a higher ranking : She also wants to know if she should start a paid ad campaign on Google too. What advice would you give her?
Calculate the final purchase price after discount : At the President's Day sale, a customer can bring in a coupon for a 10%, 20% or 30% discount off of total purchases.
Determine the value of the function pn for different value : Write a program to determine the value of the function P(n) for different values of n. The first few prime sums are 2, 5, 10, 17, 28, 41, 58 and 77.
What advice would you give her : Pretend that you are a SEO consultant hired by a new home baker who is planning on selling her products thorough the internet.
Write a driver program with a main method : Write a method named isPrime, which takes an integer as an argument and returns true if the argument is prime or false otherwise.
Write your solution using dynamically allocated arrays : Even though this assignment can be coded with statically allocated arrays, please write your solution using dynamically allocated arrays.
How can you print three rows of values on an lcd : How can you print three rows of values on an LCD using mbed at the same time for example time, date and year.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Implement a simplified version of the set class

You will implement a simplified version of the set class. You must implement all functions defined in the provided file set.h. You may add other member functions and variables as necessary.

  Using array subscript notation

Using array subscript notation, base/offset notation with the array name as the pointer, array notation with  vPtr , and pointer/offset notation with  vPtr , add 3 to the value in the 3 rd element and display that number. (Do not modify the value in ..

  Inserts a node with info value x

Complete the code for a function that inserts a node with info      value x before, and a node with info value zafter,each node with      info value y in a linked list with first node pointer p.

  Calculate the potential energy of a rock with a mass of 55

calculate the potential energy of a rock with a mass of 55 kg while sitting on a cliff that is 27 m

  Write a pseudocode statement

Assume that a program has two string variables named str1 and str2. Write a pseudocode statement that assigns an all uppercase version of str1 to the str2 variable. is str.add(str1,str2) part of it?

  Prompts the user to enter a positive decimal number

Write a C++ program that prompts the user to enter a positive decimal number, then the program finds the sum of the first and second decimal digits.

  Implement a solution to the critical section problem

Implement a solution to the critical section problem for 2 processes using mutex locks. Specifically in pthreads using pthread_mutex_trylock

  Find the pairs in any given matrix

write a c program which will find the pairs in any given matrix, whose sum of pairs are 10.

  Prepare program to check the syntax of the english language

Determine the form of the output dependent on the coefficients being input. Print and evaluate with peers in class."

  Write cpp program that will allow a user to manage inventory

Write a C++ program that will allow a user to manage the inventory of a store. The inventory for a small electronics store for example will contain the information for each item in the inventory.

  How would you put a empty space between output

How would you put a empty space between output, right now it prints 6 rows but how do i add a space or a "\n" for example row1 row2 row3

  Use and provide information with minimal difficulty

Smartphones today have changed our ability to find, use and provide information with minimal difficulty, however, in the past ten years, smartphones have changed from single user oriented to multi user connectivity. For example, in our last class tim..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd