Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function int *numSequences(std::vector *primes, int num) that takes a vector of primes, an integer of interest, and returns the number of representations for

Write a function int *numSequences(std::vector *primes, int num) that takes a vector of primes, an integer of interest, and returns the number of representations for that given positive integer.

image text in transcribed

#include #include "Primes.h"

std::vector *genPrimes(int M) { std::vector *v = new std::vector(); std::vector *t = new std::vector(M); int i=0; int nextPrime = 2;

for(i=0; i

(*t)[0]=0; (*t)[1]=0;

v->push_back(2);

while (nextPrime push_back(nextPrime); break; } }

delete t; return v; }

int numSequences(std::vector *primes, int num) {

// your code here

// code to quell compiler complaints. Delete it. return num + (*primes)[1]; }

Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations: 5 7 + 11 13 17 and 53. The integer 41 has three representations 2+3+5+7+11+13, 11+13+17, and 41. The integer 3 has only one representation, which is 3 . The integer 20 has no such representations. Note that summands must be oonseoutive prime numbers, so neither 713 nor 3 557 is a valid representation for the integer 20 Write a funotion int *numSequences (std::vector *primes, int num) that takes a veotor of primes that you learned to create for the Primes POTD, an integer of interest, and returns the number of representations for that given positive integer

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

More Books

Students also viewed these Databases questions

Question

l Describe two security benefits.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Explain the procedure for valuation of shares.

Answered: 1 week ago

Question

Which months of this year 5 Mondays ?

Answered: 1 week ago

Question

Define Leap year?

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago