Hi, friends!
I got a serious problems... Tomorrow I need to send this assignment to my professor. I tried a lot of hours but still no useful results.. :( You guys are my last hope :(!
There is an integer n.
Find numbers that:
*can be expressed in the form 2^k-1 (http://en.wikipedia.org/wiki/Mersenne_prime#List_of_known_Mersenne_primes)
*and are less than n
*and are prime.
Please try to help me to solve it! This is very important to me! :(
Here is what I got:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int OKZ;
int n = 0;
do
{
cout << "INPUT n: " << endl;
cin >> n; cout << endl;
for (int k=0; k<n; ++k) // Part of program that generates integers of the form 2^k-1
{
int n=1; // subtract one
for (int i=0; i<k; i++)
{
n=n*2;
}
n=n-1; // subtract one
}
bool OK = true;
for(int i = 0; i <= n; i++)
{
for(int j = 2; j <= n; j++)
{
if (i!=j && i % j == 0 )
{
OK=false;
break;
}
}
if (OK)
{
cout << i << endl;
}
OK = true;
}
cout << " continue (1) or end program (0)?" << endl;
cin >> OKZ; //
}
while (OKZ == 1);
return 0;
}
And here is a part to see whether or not the value is a prime number:
bool isprime(unsigned int n)
{
if (n<2)
return false;
for (unsigned int j = 2; j < n; j++)
{
if (n % j == 0 )
return false;
}
return true;
}