so as no language is specified so we will solve this problem in c++ together
as the problem is not very clear that how many values need to print so I am writing generic code that will give an answer for all n
So are u with me on this........let's do it
here is the code
// Find number a, a is positive integer and a<2000, such that
f(n) =n^2-79n +a is prime numbers for all n on [0,79]
// please include your code input and output in the answers.
#include <bits/stdc++.h>
using namespace std;
int main()
{
// so we have a range of n from [0,79]
// range of a is up to a< 2000
int n = 80;
// all prime number from a 0 to 2000 so that it can be easy to
solve it later
//so there can many values of a, when when we add it to n^2 - 79n
so I will print all the numbers
vector<int>res; // vector created to store all the prime
numbers
res.push_back(2); // push_back is used to append the value in the
vector
// this code is for find all the prime number time compexity for
this code to find all prime number is O(nlong(n))
for(int i =3;i<2000;i++){
int flag = 0;
for(int j = 2;j*j<=i;j++){
if(i%j==0){
flag = 1;
}
}
if(flag ==0){
res.push_back(i);
}
}
cout<<" prime numbers are :"<<endl; //prints all the
prime numbers
for(int i = 0;i<res.size();i++){
cout<<res[i]<<" ";
}
cout<<endl;
vector<pair<int,int>>ans; // making a pair to find for
which value of n what are the values of a that are prime
// code to find all the (a) value
for(int i = 0;i<n;i++)
{
// f(n) = n^2-79n+a
for(int j= 0;j<2000;j++){ // runs for a value
int check_val = i*i -79*i +j;
if(find(res.begin(), res.end(), check_val) != res.end()) // find if
the check_val is res or not if yes then we got our a value
ans.push_back({i,j});
}
}
cout<<"\nvalue of a when added to f(n) makes it prime for
what value of n\n"<<endl;
//ans[i].first = value of n
//ans[i].second = value of a
for(int i = 0;i<ans.size();i++){
cout<<"[ "<<ans[i].first<<"
"<<ans[i].second<<" ]"<<" " ;// prints n value
then a value when added to function makes it prime.
}
return 0;
}
output file for this is
if any doubt, comment below.
Get Answers For Free
Most questions answered within 1 hours.