Adam Lesperance >
Project-Euler >
Project::Euler::Problem::P003

Module Version: 0.20
Project::Euler::Problem::P003 - Solutions for problem 003 - Max prime factor

version 0.20

http://projecteuler.net/index.php?section=problems&id=3

use Project::Euler::Problem::P003; my $p3 = Project::Euler::Problem::P003->new; my $default_answer = $p3->solve;

This module is used to solve problem #003

Here we find the maximum prime factor of a given number. Math::Big::Factor is used to generate a prime wheel that finds all of the prime factors. From there it's a simple matter of taking the last one in the array to find the max value.

This will eventually be changed to use a custom-build prime generator to stay in the spirit of the Project Euler.

*None*

003

Max prime factor

02 November 2001

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600,851,475,143?

600,851,475,143

6857

Yes

There is little to no customization for this problem, simply tell it what you want to factor with custom_input

The restrictions on custom_input

A positive integer

Use factors_wheel to find all of the prime factors for the given number. Since the function always returns a sorted list, we can just return the last number in the returned array to find the max. In order to speed up the function whenever possible, a smaller wheel is generated if the number is less than 10 characters long

Adam Lesperance <lespea@gmail.com>

This software is copyright (c) 2010 by Adam Lesperance.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: