Question: #include #include using namespace std; int func1(int n) { // the given function 1 return n*n + n +41; } int func2(int n) { //

#include #include

using namespace std;

int func1(int n) { // the given function 1 return n*n + n +41; } int func2(int n) { // the given function 2 return n*n - 79*n + 1601; } int func3(int n, int a, int b) { // the given function 3 return n*n + a*n + b; }

int isPrime(int y){ //to check whether the number is prime or not if(y<0) { return 0; } for(int i=2; i<=sqrt(y); i++){ if(y%i==0) return 0; } return 1; }

void printPrimeswith40(){ // to print prime till n 40 for(int i=0; i<40; i++){ int j = func1(i); if(isPrime(j)) { cout<

void printPrimeswith80(){ // to print prime till n 80 for(int i=0; i<80; i++){ int k = func2(i); if(isPrime(k)) { cout<

void printMaxAB(){ // to print max a and b from given n range int a, b, c, j, n, maxa=0, maxb=0, maxn=0;

for(a=-999; a<1000; a++){

for(b=-1000; b<=1000; b++){

n=0, c=0; do{ j = func3(n, a, b); c++;n++; }while(isPrime(j));

if(n>maxn){ maxa = a; maxb = b; maxn = n; } } } cout<<"a= "<

cout<<" 80 prime numbers: "<

cout<

return 0;

}

For the above program:

1. The isPrime() function. What is the time complexity of this function?

2. Tune the program to limit variable b to prime numbers only, since when n is 0, all we have is 0*0 + a * 0 + b = b. Thus b must be a prime number.

3. Tune the code to print all consecutive prime numbers from the longest sequence.

4. And also present the implementation of Array List.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!