All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.cotelab.euler.Problem10 Maven / Gradle / Ivy

package net.sf.cotelab.euler;

import net.sf.cotelab.util.math.Primes;

/**
 * A solution for Project Euler Problem 10.
 * The problem statement is
 * here.
 * @author Al Cote'
 */
public class Problem10 {
	/**
	 * @param args unused.
	 */
	public static void main(String[] args) {
		Primes primes = new Primes();
		long sum = 0;

//		for (long candidate = 2; candidate < LIMIT; ++candidate) {
//			if (primes.isPrime(candidate)) {
//				sum += candidate;
//			}
//		}
		for (long p = Primes.FIRST_PRIME; p < LIMIT; p = primes.nextPrime(p)) {
			sum += p;
		}
		
		// 142913828922
		System.out.println("sum = " + sum);
	}

	public static long LIMIT = 2000000;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy