//ProjectEuler/Java/Problem10.java //Matthew Ellison // Created: 03-03-19 //Modified: 03-28-19 //Find the sum of all the primes below two million //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.util.ArrayList; public class Problem10{ private static final Long GOAL_NUMBER = 2000000L; public static void main(String[] argv){ Stopwatch timer = new Stopwatch(); //To time the algorithm's run time //Start the timer timer.start(); //Get the sum of all prime numbers < GOAL_NUMBER Long sum = Algorithms.getLongSum(Algorithms.getPrimes(GOAL_NUMBER - 1L)); //Subtract 1 from the number so that it is < the number //Stop the timer timer.stop(); //Print the results System.out.printf("The sum of all the primes < %d is %d\n", GOAL_NUMBER, sum); System.out.println("It took " + timer.getStr() + " to run this algorithm"); } } /* Results: */