Files
ProjectEulerJava/Problem7.java

56 lines
1.8 KiB
Java

//ProjectEuler/Java/Problem7.java
//Matthew Ellison
// Created: 03-01-19
//Modified: 03-28-19
//What is the 10001th prime number?
//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 <https://www.gnu.org/licenses/>.
*/
import mattrixwv.Stopwatch;
import mattrixwv.Algorithms;
import java.util.ArrayList;
import java.math.BigInteger;
public class Problem7{
private static final BigInteger NUMBER_OF_PRIMES = BigInteger.valueOf(10001);
public static void main(String[] argv){
Stopwatch timer = new Stopwatch(); //So the algorithm can be timed
//Start the timer
timer.start();
//Setup the variables
ArrayList<BigInteger> primes = Algorithms.getNumPrimes(NUMBER_OF_PRIMES); //Holds the prime numbers
//Stop the timer
timer.stop();
//Print the results
System.out.println("The " + NUMBER_OF_PRIMES.toString() + "th prime number is " + primes.get(primes.size() - 1));
System.out.println("It took " + timer.getStr() + " to run this algorithm");
}
}
/* Results:
The 10001th prime number is 104743
It took 142.783 milliseconds to run this algorithm
*/