|
-
Sep 15th, 2009, 06:24 PM
#41
Re: The first 50,000 prime numbers, enjoy :)
 Originally Posted by TriLogic
As the ratio of prime numbers diminishes in relation to increase in numbers then we would have to project eventual 0% --> infinity. But it is proven that primes are infinite and we have no reason to believe that the ratio will ever become fixed. So what happens after .001% as N --> infinity.
That may be true as long as the curvilinear function is continuous and you can wait forever. But, let's be realistic. Assume we can calculate primes for several years with today's high speed computers as Storm is doing. Then go up a notch and use a Cray. I have a feeling that you would still never obtain in your lifetime a ratio of (Number of Primes / Largest Prime) that was less than 0.05.
I am judging this based on Storm's findings alone, and that's rather good empirical evidence. Can anyone find a published discussion of this ratio: (Number of Primes / Largest Prime)? If so, what is your conclusion?
-
Sep 15th, 2009, 07:30 PM
#42
Hyperactive Member
Re: The first 50,000 prime numbers, enjoy :)
This is the straight forward algorithm I can come up with. I am sure there are ingenious algorithms that are super weird, but fast. Does anyone know what kind of algorithm software like mathematica uses?
Code:
int* primes = new int[500000];
primes[0] = 2;
int primesCount = 1;
int testNumber = 3;
cout << "Begin." << endl;
while (primesCount < 500000)
{
int maxTest = (int)sqrt((float)testNumber);
bool isPrime = true;
for (int i = 0; primes[i] <= maxTest; i++)
{
if (testNumber % primes[i] == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
primes[primesCount] = testNumber;
primesCount++;
}
testNumber += 2;
}
cout << "Last prime calculated: " << primes[499999] << endl;
cin.get();
delete[] primes;
My code doesn't do anything with the primes it calculates except show the last one. But it could easily be changed to output the numbers to a file or something.
My monkey wearing the fedora points and laughs at you.
-
Sep 15th, 2009, 08:31 PM
#43
Hyperactive Member
Re: The first 50,000 prime numbers, enjoy :)
 Originally Posted by Arrow_Raider
This is the straight forward algorithm I can come up with. I am sure there are ingenious algorithms that are super weird, but fast. Does anyone know what kind of algorithm software like mathematica uses?
Code:
int* primes = new int[500000];
primes[0] = 2;
int primesCount = 1;
int testNumber = 3;
cout << "Begin." << endl;
while (primesCount < 500000)
{
int maxTest = (int)sqrt((float)testNumber);
bool isPrime = true;
for (int i = 0; primes[i] <= maxTest; i++)
{
if (testNumber % primes[i] == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
primes[primesCount] = testNumber;
primesCount++;
}
testNumber += 2;
}
cout << "Last prime calculated: " << primes[499999] << endl;
cin.get();
delete[] primes;
My code doesn't do anything with the primes it calculates except show the last one. But it could easily be changed to output the numbers to a file or something.
You're using a memory array. That's fine if you want a short list. Could this array hold over 422 million elements of 64-bit unsigned length? No. So, you see, this is not a practical way.
I have no limit on number size or numbers to find. It's all to infinity.
I can't read C++ very well, and can write none.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|