Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93090705

Have any Question?


Related Questions in Computer Engineering

Should you perform a log transformation on a categorical

Should you perform a log transformation on a categorical (nominal) variable, or can you only do that for continuous variables?

In linux what synchronization methods they use within the

In Linux what synchronization methods they use within the kernel, please dig into your findings for Linux.

At a certain temp the kp for the decomposition of h2s is

At a certain temp, the Kp for the decomposition of H2S is .883. H2S (g) ----> H2(g) + S (g) Initially, only H2S is present at a pressure of  .181 atm  in a closed container. What is the total pressure in the container at ...

Question 1 identify the three main types of computer

Question: 1. Identify the three main types of computer software that were discussed in your unit lesson. Within the three main categories, give examples of each and a brief explanation of each. Each explanation/descripti ...

For this assignment you will produce a reflection paper

For this assignment, you will produce a reflection paper based on your experience in the BSIT program, and in preparation for developing a professional portfolio starting next week. The purpose of the reflection paper is ...

Biodiversity refers to the variety of living organisms

Biodiversity refers to the variety of living organisms found within an ecosystem. In your description, evaluate the role of humans in the current biodiversity loss situation and increased species extinction rate. In addi ...

Assume that the pizza market consists of two firms conans

Assume that the pizza market consists of two firms, Conan's and Pizza Hut. The price of a Conan pizza is denoted by Pc and the price of a Pizza Hut Pizza is P h.  Both sellers have a marginal cost of $5 for another pizza ...

Discuss honeypots are they legal should they be legal what

Discuss honeypots. Are they legal? Should they be legal? What are some of the potential problems for those implementing a honeypot?

Task you want to calculate a students gpa for a number of

Task: You want to calculate a student's GPA for a number of classes taken by the student during a single semester. (In C# (C sharp)) Inputs: 1. the student's name 2. Class names for the classes taken by the student 3. Cl ...

Remembering the pythagorean theorem - the square of the

Remembering the Pythagorean Theorem - The square of the hypotenuse is equal to the sum of the squares of the other two sides Your assignment is to design a Fortran 95 program with three solutions for the quadratic equati ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As