cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Efficient algorithm for finding large pr
Efficient algorithm for finding large prime factors
May 2, 2012 at 3:31am UTC
ResidentBiscuit
(4459)
Ok so I kind of went all brute force with this problem, and it takes forever to find a result. I was wondering what all good algorithms and/or tricks there are to finding large prime factors
May 2, 2012 at 3:38am UTC
JLBorges
(13770)
http://en.wikipedia.org/wiki/Integer_factorization#Factoring_algorithms
May 2, 2012 at 4:04am UTC
ResidentBiscuit
(4459)
Thanks for the link, but I am having a hell of a time finding the largest prime factor of a number. Is this generally a hard task?
May 2, 2012 at 4:10am UTC
JLBorges
(13770)
Depends. How big is the number? (How many decimal digits?)
May 2, 2012 at 4:22am UTC
ResidentBiscuit
(4459)
12 decimal digits for this number. It's project Euler number 3. I've had a few ideas as to how to do it, but none seem very efficient
May 2, 2012 at 4:39am UTC
JLBorges
(13770)
That should be trivial. (It can be held in a std::uint_fast64_t).
In a loop,
1. Divide the numbers by prime numbers 2, 3, 5, 7, ...
2. Check if the result is of the form
6n-1
or
6n+1
( all prime numbers greater than 3 are of the form 6n-1 or 6n+1)
3. If it is, perform a deterministic Miller-Rabin primality test on it.
http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test#Deterministic_variants_of_the_test
Topic archived. No new replies allowed.