Write a program that takes a 3 digit number n and finds out
whether
the number 2^n + 1 is prime, or if it is not prime find out its
factors.

Answer Posted / srikanthgowda

#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;

int main()
{

int n,a[100];
cout<<"Enter size of the array"<<endl;
cin>>n;

cout<<"Enter the any value in 3digit format"<<endl;
for (int i=0;i<n;i++)
cin>>a[i];

for (int i=0;i<n;++i)
{

if((a[i]/100)>10)
{
cout<<"invaild"<<endl;
exit(0);
}
}

cout<<"Vaild within 3idigit number"<<endl;


int temp=pow(2,a[n-1]);
temp=temp+1;
cout<<temp;
int count=0;
for(int i=1;i<=1000;i++)
if( (temp)%i == 0 )

{
count++;
}


if (count==2)
{
cout<<endl<<temp<<"-->%2^n+1%"<<"is prime number"<<endl;
}
else
{
cout<<endl<<temp<<" is not primre number
";
}


return 0;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Performance Algorithm A performs 10n2 basic operations and algorithm B performs 300 lg n basic operations. For what value of n does algorithm B start to show its better performance?

7341


solve the problem in the programming language C++"if a five digit number is input through the keyboard.Write a program to calculate the sum of its digits(hint: use the modulus operator)

2935


write a program to calculate the amount of investment after a period n years if the principal investors was p and interest is calculated using compound interest,formular=a=p(1+r)^n

2366


how to take time as input in the format (12:02:13) from user so that controls remains between these columns?

1817


Write a simple encryption program using string function which apply the substitution method.

5538






Write a (n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)

4451


what mean void creat_object?in public class in this code class A{ public: int x; A(){ cout << endl<< "Constructor A";} ~A(){ cout << endl<< "Destructor A, x is\t"<< x;} }; void create_object(); void main() { A a; a.x=10; { A c; c.x=20; } create_object(); } void create_object() { A b; b.x=30; }

2066


How to swap two ASCII numbers?

2449


Question 1: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date. *This Should Be Done IN C++

550


i really need help about this.. write a program to display the set of odd and even numbers separately. find the highest and lowest value of the given numbers.

1970


We need to write the function to check the password entered is correct or not based on the following conditions.. a) It must have atleast one lower case character and one digit. b)It must not have any Upper case characters and any special characters c) length should be b/w 5-12. d) It should not have any same immediate patterns like abcanan1 : not acceptable coz of an an pattern abc11se: not acceptable, coz of pattern 11 123sd123 : acceptable, as not immediate pattern adfasdsdf : not acceptable, as no digits Aasdfasd12: not acceptable, as have uppercase character

3957


Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).

3193


Code for Two Classes for Doing Gzip in Memory?

2814


write a program that can LOCATE and INSERT elements in array using c++ programming languages.

3436


write a function that allocates memory for a single data type passed as a parameter.the function uses the new operator and return a pointer to the allocated memory.the function must catch and handle any exception during allocation

2404