Thread: Prime Numbers, Modulus Operator Help

  1. #31
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by abachler View Post
    As for padding, personally I use a much faster although more convoluted method of updating Root that bypasses the slow SQRT() function. Since im assuming the teacher will not enter some obtusely large number for the count of primes to find ( like 200 million) runtime shouldnt be an issue.
    You don't need to use sqrt() to do the optimization.

    Code:
    result = possible_prime / possible_factor;
    if(result < possible_factor)
    {
        /* Obviously, we've crossed the square root at this point. */
    }

  2. #32
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    HEY you've been looking at my notes

    Actually I just do that step to determine if I need to Root++

    Code:
    if(Prime / Root > Root) Root+=2;
    different implementation, btu the same core method. The reason I increase root by 2 is we will only be checking odd number factors anyway.
    Last edited by abachler; 02-07-2008 at 09:26 AM.

  3. #33
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by vart View Post
    too optimized
    then try this -

    Code:
    if(!(Prime & 1)) return FALSE;

  4. #34
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by abachler View Post
    then try this -

    Code:
    if(!(Prime & 1)) return FALSE;
    it was a joke, checking Prime in any way will do you no good here... As was said - you need to test the value of Target
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #35
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    oh gawd, yeah i totally missed that one, it shodul be

    Code:
    if(!(Target & 1)) return FALSE;
    thanks for catching that nub mistake vart

    BTW, for anyone that tried to D/L the primes in the last few days and got a service message, the site is back up and running. Sorry I forgot to pay the bill
    Last edited by abachler; 02-07-2008 at 03:21 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. prime numbers, counters, help!
    By vege^ in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2003, 04:32 PM
  3. More Prime Numbers
    By mmuhlenb in forum C Programming
    Replies: 3
    Last Post: 02-21-2003, 10:06 AM
  4. Prime numbers
    By Lazy Student in forum C Programming
    Replies: 12
    Last Post: 05-14-2002, 05:53 AM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM