Tuesday, August 11, 2009

Basic Math premises..useful to tackle algorithm problems

As I have solved many algorithm problem, either just out of interest or to prepare for interviews, I have realized that these basic math premises are quite handy. We have all learnt these in school/college etc. but we often forget these basics and do not write efficient algorithms. Feel free to suggest more to add to the list..
  1. Every whole number can be represented by the product of a unique combination of prime numbers.    E.g. 48 = 2^4 x 3, 46 = 2 x 23
  2. To confirm if a number is a prime or not, it is enough to check if there exists a factor between 2 and the sqrt(number). No need to check until number-1.
  3. A factorion is an integer which is equal to the sum of factorials of its digits. There are exactly four such numbers:
    1=1!

    2=2!

    145=1!+4!+5!

    40585=4!+0!+5!+8!+5!

No comments:

Post a Comment