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
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?
Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).
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++
find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L
Code for Two Classes for Doing Gzip in Memory?
Ask the user to input three positive integers M, N and q. Make the 2 dimensional array of integers with size MxN, where all the elements of I (I = 1,…,M) line will be members of geometrical progression with first element equal to the number of line (I) and denominator q.
How to Split Strings with Regex in Managed C++ Applications?
Code for Method of Handling Factorials of Any Size?
write a program that reads a series of strings and prints only those strings begging with letter "b"
Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?
What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }
Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37
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; }
Code for Easily Using Hash Table?
write a program using virtual function to find the transposing of a square matrix?