Page 2 of 2 FirstFirst 12
Results 41 to 43 of 43

Thread: The first 50,000 prime numbers, enjoy :)

  1. #41
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Question Re: The first 50,000 prime numbers, enjoy :)

    Quote Originally Posted by TriLogic View Post
    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?
    Doctor Ed

  2. #42
    Hyperactive Member Arrow_Raider's Avatar
    Join Date
    Dec 2001
    Location
    AVR Lovers Club
    Posts
    423

    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 &#37; 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.

  3. #43
    Hyperactive Member storm5510's Avatar
    Join Date
    Jul 2009
    Location
    Indiana, U.S.A.
    Posts
    329

    Re: The first 50,000 prime numbers, enjoy :)

    Quote Originally Posted by Arrow_Raider View Post
    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.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width