Algorithms in Ruby: Largest Prime Factor

If we want the largest prime multiple of 10, and the first prime number is 2, and when divided, is 5, with no remainder. Then, next prime multiple is 5. If we take the quotient of 5 and divide it by the prime multiple, 5, we get 1. Therefore, we have found the largest, but also the last prime number that will satisfy. Stop doing work, and return that last prime.
def lpf(n)   p Prime.prime_division(n)endlpf(600851475143)# prints: [[71, 1], [839, 1], [1471, 1], [6857, 1]]
def lpf(n)p Prime.prime_division(n).last[0]endlpf(600851475143)#prints: 6857

--

--

--

web developer making apps for people with appetite

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The 2 Parameter Binomial Discrete Distribution 4 Formulas

Volatility Models

Visualizing The Product Rule

The discrete Charm of Continuous Math

Mechanics: Oblique Collisions

Assignment on Bootstrap and Miller Circuits. Adimike Stanley (2018364071)

Are You Smart Enough For A Scholarship?

The Hardy-Hilbert Space of the Unit Disc and Composition Operators

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
aaron feingold

aaron feingold

web developer making apps for people with appetite

More from Medium

How to Create Static Library in C and How to Use it.

Structures and Unions in C

10 mistakes to avoid when using std::vector

Sorting Techniques 2.0