Friday, May 1, 2009

Prime Factors Calculator

I made this javascript prime factors calculator and have found it addictive. I just keep factorizing numbers. Enter the number to factorize in the left box and click on the 'factorize' button. The prime factors are shown in the right box.

I've never had a push button prime factor generator before.

You can easily check if a number is prime. It only has one prime factor: itself.

It's easy to generate a large prime number. Just type in a long random number and get its prime factors. If one of the factors is large, you've found a large prime number. If you don't get one, try changing your random number slightly.

For example: 384339387 gives 3,37,3462517. So 3462517 is a nice large prime number.

I like adding an extra digit and seeing what factors come out:

numberprime factors

All the numbers with an even number of ones have the factor 11. And those with 4, 8 and 12 ones have factors of 11 and 101 because 1111 = 11 X 101.

Those with an odd number of ones have only two prime factors, except 111111111 (nine ones). I wonder if there's something going on here?

Oh no, the next number lets me down: 1111111111111 has factors 53,79 and 265371653.

If you find any interesting patterns with this prime factors calculator, let me know.


  1. nice toy for very small numbers =)
    try this number: 2287930740466177.
    You'll get correct answer, but you have to wait. Now try this one: 1569079426997587189. The answer of your script is incorrect.

  2. Hmmmm. When I put in 1569079426997587189 it gives me the factors for 1569079426997587200.

    With a bit of trial an error I've found that it seems to work for numbers up to 2**53 = 9007199254740992

    The limitation is either with Javascript's Math.abs() or parseInt() function or both. This is changing the input number before it is factorized. I'll have a look when I get some more time...

    "I can't factor that number, but here's one I can do".

  3. Even without the Math.abs() and parseInt() the calculation still fails for 2**53 + 1. So I've put in a limit with a maximum number of 2**53 - 1.

    I would have made 2**53 the maximum, as it factors this ok, but the '>' comparison in Javascipt can't tell the difference between 2*53 and 2*53 + 1.

    (2**53 + 1) > (2**53) returns false in Javascript!

  4. > If you find any interesting patterns with this prime factors calculator, let me know.

    If I found a pattern in primes, I'd tell you right after my Nobel prize :P

  5. for 111111111 3,3,37,333667

    but 333667 is NOT prime!!

  6. If 333667 is not prime, what are its divisors?

  7. I like trying phone numbers.