1 / 9

Prime Numbers & Hamming numbers

Prime Numbers & Hamming numbers. A combination of two similar yet different madness…. int getPrimeFactor. Basic concepts If a number is even, apart from 2 it is not a prime If a number is odd, its factors can be 3, 5, 7, 9, … We can essentially eliminate all the even factors

liana
Download Presentation

Prime Numbers & Hamming numbers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Prime Numbers & Hamming numbers A combination of two similar yet different madness…

  2. intgetPrimeFactor • Basic concepts • If a number is even, apart from 2 it is not a prime • If a number is odd, its factors can be 3, 5, 7, 9, … We can essentially eliminate all the even factors • *** (Extra info.) The number is a prime if all factors up till sqrt (number) is not divisible by that number • E.g. number is 61, if 2, 3, 4, 5, 6, 7, 8 cannot divide the number, then there is no way another factor can occur in the range 9 to 61.

  3. intgetPrimeFactor

  4. void printPrimeFactors • Basic concepts: • A number still has factors if it is not 1 • For the current number, print out its smallest factor • Then divide the number by its factor • Repeat the process until the number is 1 • *** (Optional) To print out the “x”, check if the number is not 1 (means still have factors) and print out “ x “.

  5. void printPrimeFactors

  6. intisHammingNumber • Basic concepts: • Divide the number by 2 repeatedly until it has no more factors of 2 • Repeat the process for 3 and 5 • If the resultant number is 1, means the number has no other factors and is a Hamming Number

  7. intisHammingNumber

  8. Input and Output

  9. Thanks 

More Related