NAME

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

VERSION

version 0.20

HOMEPAGE

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

SYNOPSIS

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

my $default_answer = $p3->solve;

DESCRIPTION

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.

Problem Attributes

*None*

SETUP

Problem Number

003

Problem Name

Max prime factor

Problem Date

02 November 2001

Problem Desc

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

Default Input

600,851,475,143

Default Answer

6857

Has Input?

Yes

Help Message

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

INTERNAL FUNCTIONS

Validate Input

The restrictions on custom_input

A positive integer

Solving the problem

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

AUTHOR

Adam Lesperance <lespea@gmail.com>

COPYRIGHT AND LICENSE

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.