Finding the largest prime factor on the 15c - Printable Version +- HP Forums ( https://archived.hpcalc.org/museumforum)+-- Forum: HP Museum Forums ( https://archived.hpcalc.org/museumforum/forum-1.html)+--- Forum: Old HP Forum Archives ( https://archived.hpcalc.org/museumforum/forum-2.html)+--- Thread: Finding the largest prime factor on the 15c ( /thread-232372.html) |

Finding the largest prime factor on the 15c - Evan Gates - 10-03-2012
I recently had reason to learn how to program my 15c (LE), and had heard that Project Euler is a good way to familiarize oneself with a new programming language/environment. Problems 1 and 2 were trivial, but I had fun with problem 3, finding the largest prime factor of a number. Unfortunately the actual number given is two digits too long for the 15c (600851475143). To use, key the number to test into the x register then run the program. When the program has finished the largest prime factor will be in the x register. As I'm new to programming the 15c, I'd love any advice, and be interested in more efficient solutions (both speed and size improvements) if anyone is interested.
001-42,21,11 f LBL A Re: Finding the largest prime factor on the 15c - Jim Horn - 10-03-2012
A few minor suggestions. In "LBL 1", the divisibility test, you take the square root of Register 0. I'd advise taking that square root when you store Register 0, saving that in Register 1. That way, you'll not have to do myriad square roots, a relatively slow operation. You can also speed the test slightly by using a modulo-30 or modulo-210 test (eliminates divisions by multiples of 5 and 7), just as you do now with modulo-6. Back in the '70s we beat the dickens out of this subject to get every clock cycle out of this type of code (the HP-67 took 3 hours 45 minutes to discover that 9999999967 was prime). Fascinating that the WP 34S "isprime" returns that same result in under a second! As I don't have and have never used an HP-15, I can't say much about how to do the divisibility test as fast as possible on same. But there are some tremendous contributors on this forum who will undoubtedly dive in.
Any takers?
Re: Finding the largest prime factor on the 15c - Thomas Klemm - 10-03-2012
LBL A
My changes are: - Use the stack to pass parameters to subroutine.
- Changed exit-condition: reuse value
*R.0 / R.I*.
Kind regards |