Help: How to write a prime number greater than one billion

This is a discussion on Help: How to write a prime number greater than one billion within the C++ Programming forums, part of the General Programming Boards category; My question is like I am clueless. And how I can write such as program that the first prime number ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    65

    Help: How to write a prime number greater than one billion

    My question is like I am clueless. And how I can write such as program that the first prime number is greater than one billion?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,910
    Basically, you are supposed to implement a program that finds primes greater than one billion? What ideas do you have? What do you know about primality testing?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    65
    As far as I know...Finding a prime needs to use the if-statement with a comparison operator == with the divisor of remainder. That's, if(something % something == 0) is not prime. So there is must be a remainder. I am just clueless as my level is not up to that or maybe I am just at the end of my wit.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You've got prime number testing code, right? You've posted it before. Why do you expect this to be in any way, shape, or form different?

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    I assume he has encountered the problem of integer overflows .

    I think you used a simple int in your code? It's maximum value is around 2 billion. An unsigned int would increase it to 4 billion. You could also use a "long long int"; or an "unsigned long long int", which have way higher maximums. If these limits are still too low, you'll have to use a big integer class.

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    If I'm not mistaken long long is currently non-standard (but is going to make it in soon), so if the compiler supports it, go ahead.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    long long is "merely" C99.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem running prime number test.
    By galactic_ronin in forum C++ Programming
    Replies: 25
    Last Post: 02-20-2008, 11:21 AM
  2. for loop to find prime numbers
    By 1rwhites in forum C Programming
    Replies: 11
    Last Post: 10-21-2005, 10:37 AM
  3. how to calculate billion number
    By mrmamon in forum C++ Programming
    Replies: 9
    Last Post: 10-16-2005, 06:34 AM
  4. Prime Number stops after 29, but why?
    By Daveo in forum C Programming
    Replies: 22
    Last Post: 09-17-2004, 10:55 AM
  5. How is to check prime number?
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 10-04-2001, 11:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21