Wracked my brains for over half a day on this one to arrive at some definitive conclusion....
The problem statement is to find the Nth prime above a certain threshold number.
For example, find the 306th prime no.
Here is the solution :
//Find the Nth prime number above 50...
int nc=0;
int j = 50;
while (true)
{
j += 1;
if ((j % 2) == 0)
{
continue;
}
else if (((j % 3) == 0))
{
continue;
}
else if (((j % 5) == 0))
{
continue;
}
else if (((j % 7) == 0))
{
continue;
}
else if (((j % 11) == 0))
{
continue;
}
else if (((j % 13) == 0))
{
continue;
}
else if (((j % 17) == 0))
{
continue;
}
else if (((j % 19) == 0))
{
continue;
}
else if (((j % 23) == 0))
{
continue;
}
else if (((j % 29) == 0))
{
continue;
}
else if (((j % 31) == 0))
{
continue;
}
else if (((j % 37) == 0))
{
continue;
}
else if (((j % 41) == 0))
{
continue;
}
else
{
goto DD;
}
DD:
nc+=1;
if (nc == 292)
{
break;
}
}//loop
MessageBox.Show("Prime No - " + ((nc-1)+15).ToString() + " Equals " + j.ToString());
There are two major points about the above code :
1)It will give accurate results for numbers < (452). This represents the arithmetic mean of the next two higher prime numbers (43 and 47) that are not listed.
2)The arithmetic mean in point 1 will always be an integer (not a decimal fraction).
The problem statement is to find the Nth prime above a certain threshold number.
For example, find the 306th prime no.
Here is the solution :
//Find the Nth prime number above 50...
int nc=0;
int j = 50;
while (true)
{
j += 1;
if ((j % 2) == 0)
{
continue;
}
else if (((j % 3) == 0))
{
continue;
}
else if (((j % 5) == 0))
{
continue;
}
else if (((j % 7) == 0))
{
continue;
}
else if (((j % 11) == 0))
{
continue;
}
else if (((j % 13) == 0))
{
continue;
}
else if (((j % 17) == 0))
{
continue;
}
else if (((j % 19) == 0))
{
continue;
}
else if (((j % 23) == 0))
{
continue;
}
else if (((j % 29) == 0))
{
continue;
}
else if (((j % 31) == 0))
{
continue;
}
else if (((j % 37) == 0))
{
continue;
}
else if (((j % 41) == 0))
{
continue;
}
else
{
goto DD;
}
DD:
nc+=1;
if (nc == 292)
{
break;
}
}//loop
MessageBox.Show("Prime No - " + ((nc-1)+15).ToString() + " Equals " + j.ToString());
There are two major points about the above code :
1)It will give accurate results for numbers < (452). This represents the arithmetic mean of the next two higher prime numbers (43 and 47) that are not listed.
2)The arithmetic mean in point 1 will always be an integer (not a decimal fraction).
Comments