I think I found another algorithm for number factorization

Viewed 133

A few days ago i thought a new algorithm (maybe it is just new for me and it has already been developed ) of number factorization
My main idea is like that: For example lets say we want to find factors of N = 148261;
so we need two numbers lets say ending with abc and def :

...abc * ...def = 148261  //(Equation.1)

(...+100*a+10*b+c) * (...+100*d+10*e+f) = 148261 //(Equation.2)

If we look this Equation2 with (mod 10) we find :

c*f = 1 mod(10)

Since c and f is digit (0<=..<=9) we do brute force on this range and find possible cases of (c,f) as :

(c,f) => (1,1) (3,7) (7,3) (9,9)

OK this was step 1 - we found last digits of the factors
Lets continue on step 2
For each possible cases of (c,f) lets try to find the previous digits

  • case (c,f) = (1,1):
    if we look at the Equation2 with mod 100 and brute force b and e values we find that:
    -- (b,e) => (1,5) (2,4) ...etc...
  • case (c,f) = (3,7):
    ....

If we continue this procedure recursively up to step 6 (since 148261 is 6 digits long) we found possible factors:

173 * 857 = 148261
857 * 173 = 148261

It is recursive and its recursion degree is equals to the digits long of n which is log(10,n)
I have implemented this recursive algorithm with C#. It returns 1 * N and N * 1 if N is prime .
You can find source code (here) in my github repo. It is long enough not to write full source here

I have written unit tests to see if this is working and seems all is right and my question is not about false positive or true negative responses of this algorithm because it works as described

Now it is interesting for me - my first question - is this algorithm has a known name or developed by someone else - i would like to know more about

And I have done some performance tests such that I can find all factors of n = int.MaxValue = 2147483647 in just a 0.2 second in my laptop
I am quite impressed of the results

so i increased range and find this performance scale

  • 2^20->00:00:00.0164829
  • 2^25->00:00:00.0331482
  • 2^30->00:00:00.3606766
  • 2^35->00:00:00.7528593
  • 2^40->00:00:08.8903395
  • 2^45->00:02:13.2954906

As you can see there is much more increase of time after n=2^30 and it is not bcs of algorithm itself it is because i used uint64 and it hits its limits to calculate inner sums and products
after 2^30 i converted it to System.Numerics.BigInteger so this caused performance hits
and my second question is how to calculate O notation value of this algorithm
Just want to compare this to existing algorithms

Then I looked up the inner values of digits and find interesting case : the possible cases of inner digits is increasing up to maxStep/2 then decreases for example n = int.MaxValue = 2147483647 the inner item counts become :

  • step-1 yield 5 items
  • step-2 yield 5 items
  • step-3 yield 40 items
  • step-4 yield 400 items
  • step-5 yield 4000 items
  • step-6 yield 21882 items
  • step-7 yield 6248 items
  • step-8 yield 1028 items
  • step-9 yield 112 items
  • step-10 yield 22 items

and my third question is how do we calculate (maybe a prebuild formula?) these inner counts for given n
0 Answers
Related