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
1111
1113,37
111111,101
1111141,271
1111113,7,11,13,37
1111111239,4649
1111111111,73,101,137
1111111113,3,37,333667
111111111111,41,271,9091
1111111111121649,513239
1111111111113,7,11,13,37,101,9901

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.

7 comments:

  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.

    ReplyDelete
  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".

    ReplyDelete
  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!

    ReplyDelete
  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

    ReplyDelete
  5. for 111111111 3,3,37,333667

    but 333667 is NOT prime!!

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

    ReplyDelete
  7. I like trying phone numbers.

    ReplyDelete