uber elementary math in programming, please help

Discussion in 'OT Technology' started by nietsni3, Oct 27, 2004.

  1. nietsni3

    nietsni3 Guest

    math in programming, please help

    could anyone show me an algorithm to test if a input number is prime or not. thing is that i knew an algorithm already (the easiest one - keep dividing the input number with numbers smaller than its squaroot), but i want to know if there is a better alg out there. i just need the algorithm, you dont have to write the code for me :)
    thanks
     
    Last edited by a moderator: Oct 27, 2004
  2. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
    The way you describe is the only way I have done it in the past. Unless you are dealing with huge input numbers, that algorithm should work fine.
     
  3. nietsni3

    nietsni3 Guest

    the prof wants the class to think of a better method. at first i thought the method i described was the best one. however, one of us has thought of dividing only ODD numbers < squaroot of input number, which is a much more sotisphicated way. that changes my opinion and convinces me that there would be even a better way than that
     
  4. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
  5. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    My great uncle (who has a physics degree I think and really likes number theory) taught me one once. It has something to do with the square root of 6 I think. I was too young to understand it at the time, and I don't remember it now, but there definetely is a simple way.
     

Share This Page