Thread: Prime Prime Prime Help Help Help

  1. #16
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Which rule restricted answering to this thread? 5?
    We should see the goal of the rule. It wants to prevent dead topics to come on first page. Answering to an unanswered thread is different. For example maybe I have had asked a very hard question that nobody could answered, but 5 months later somebody came and answered it. You think it is illegal? Of course it is not. It is the goal of the forum.
    Last edited by siavoshkc; 01-20-2006 at 01:12 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #17
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    Quote Originally Posted by mltngpot
    all prime numbers (except 2) are prime, once again wasting precious processes.
    shouldn't that read, all prime numbers, other than 2, are odd. ?

    so testing for if it is odd, then seeing if it has ANY divisors other than 1 and itself is all you need to do. [ test for division by 2, 3, 5 ]
    iand non prime number with divide by one or more of these three.
    not all odd number have a square root that is an integer. ie: 15 is not prime, yet does not square root either to an integer. so testing for a square root is not going to result in a prime number.
    Quote Originally Posted by Jeff Henager
    If the average user can put a CD in and boot the system and follow the prompts, he can install and use Linux. If he can't do that simple task, he doesn't need to be around technology.

  3. #18
    Registered User mltngpot's Avatar
    Join Date
    Jan 2006
    Posts
    5
    sorry, not thinking, all prime numbers are odd except two.
    and no prime number will have an integer sqrt, however, getting the sqrt of the number before hand will eliminate checking the sqrt multiple times. any program like this, is going to be run (most likely) using large numbers, since the small ones are readily available and the math is easy. 2, 3, 5, 7, 11.... so the amount of processes run cuts down signifigantly.

    if you had say
    Code:
      sqrtnum = sqrt(iNum);
      for (count = 0; count < sqrtnum; count++)
    you would cut down on the execution of the sqrt. you could even make it faster, by checking to see if sqrtnum was an integer before the loop, so in the case of iNum being 100, the sqrt would be 10, thus skipping the loop. and making the function exponentially faster. in this case, it would skip running the loop 10 times, (or 4 times faster if you only check against prime numbers), and if you wanted to get really smart, you would do a check against 2 and 5 also before the loop, and only check numbers ending in 1, 3, 7,9 because if its even its composite as well as if it ends in 5.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculating prime factor of a huge number.
    By Bakster in forum C Programming
    Replies: 15
    Last Post: 02-20-2009, 12:06 PM
  2. prime number program with function
    By mackieinva in forum C Programming
    Replies: 17
    Last Post: 09-20-2007, 08:36 AM
  3. prime numbers, counters, help!
    By vege^ in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2003, 04:32 PM
  4. Prime Wonder
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-07-2002, 11:49 PM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM