//ProjectEuler/Java/Problem3.java //Matthew Ellison // Created: 03-01-19 //Modified: 03-28-19 //The largest prime factor of 600851475143 //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* Copyright (C) 2019 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ import mattrixwv.Stopwatch; import mattrixwv.Algorithms; import java.math.BigInteger; import java.util.ArrayList; public class Problem3{ private static final BigInteger NUMBER = BigInteger.valueOf(600851475143L); public static void main(String[] argv){ Stopwatch timer = new Stopwatch(); //A timer to check execution time of the algorithm //Start the timer timer.start(); //Get all the factors of the number ArrayList factors = Algorithms.getFactors(NUMBER); //The last element should be the largest factor //Stop the timer timer.stop(); //Print the results System.out.printf("The largest factor of the number %d is %d\n", NUMBER, factors.get(factors.size() - 1)); System.out.printf("It took %s to run this algorithm\n", timer.getStr()); } } /* Results: The largest factor of the number 600851475143 is 6857 It took 674.398 milliseconds to run this algorithm */