Problem 3

Statement
The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Solution
The code, in Ruby.

class Bignum
  def maxFact
    a = self
    b = 2
    m = 0
    while b<a+1
      if a%b==0
        m=b
        a/=b
      else
        b+=1
      end
    end
    return m
  end
end

puts 600851475143.maxFact

Answer
6857

No tags for this post.

SPEAK / ADD YOUR COMMENT
Comments are moderated.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>