I have been trying to solve this question for a very long time: https://www.spoj.com/problems/FACT2/ (29 digits), I have already solved the task with smaller constraints (19 digits).
My implementation
Prime_factorization (num):
prime_factor = pollard_rho (num)
while (miller_rabin( prime_factor) != true):
prime_factor = miller_rabin( prime_factor )
while num%prime_factor == 0:
num /= prime_factor
Here pollard-rho guesses a suitable prime factor and miller-rabin checks if returned factor is a prime.
My implementation (Code, C++) : https://github.com/forgotter/Snippets/blob/master/prime_factorization.cpp
Bugs in current implementation:
The prime-numbers used in miller-rabin needs to be more, to check for higher constraints.
Overflow (maybe)
I would like to know
How to make my code more faster
How to handle inputs larger than 10^18 (should I write one library for myself which can perform basic operations (+,-,*,/) on string.
Also, if someone can provide with a good tutorial on quadratic sieve. And with implementation would be too good to have.
Thanks for reading.
P.S: This is my first blog post. Please ignore minor mistakes.
Thanks forgotter.
Nice post. I can see in the submission status of the problem that TLE has already solved this problem. Would you like to share your idea please ? Thanks in advance.
'handle inputs larger than 10^18':
just use __int128
.There's nothing special: I myself wrote a pretty bad quadratic sieve while it seems a good pollard rho can already pass. I learnt all concepts just in wikipedia so I'm not sure I understood the concept clearly since my implementation is very very slow. (sad fact: a good pollard rho is 3 times faster than my quadratic sieve)
You can see some codes of factorization here (I uploaded this problem: factorize n = pq ≤ 1030, p and q are different primes)
Thanks a lot. :)
I am trying to solve both the questions now. :D
Most of solutions implemented a 256 bit struct (Now I know the bug in my code). Those links seems to be very useful. A lot of nifty tricks to learn.