10 Summation of primes - Project Euler
来源:互联网 发布:淘宝助理新建宝贝 编辑:程序博客网 时间:2024/05/21 08:49
package xxx.xxx.xxx;
import java.math.BigInteger;
/*
* The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
* Find the sum of all the primes below two million.
*/
public class SummationOfPrimes {
private void compute(int range){
BigInteger sum = BigInteger.valueOf(2);
for(int i = 3; i< range; i++){
boolean isPrime = true;
for(int j = 2; j<i; j++){
if(i%j==0){
isPrime = false;
break;
}
}
if(isPrime){
System.out.println(i);
sum = sum.add(BigInteger.valueOf(i));
}
}
System.out.println(sum);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SummationOfPrimes summationOfPrimes = new SummationOfPrimes();
summationOfPrimes.compute(2000000);
}
}
import java.math.BigInteger;
/*
* The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
* Find the sum of all the primes below two million.
*/
public class SummationOfPrimes {
private void compute(int range){
BigInteger sum = BigInteger.valueOf(2);
for(int i = 3; i< range; i++){
boolean isPrime = true;
for(int j = 2; j<i; j++){
if(i%j==0){
isPrime = false;
break;
}
}
if(isPrime){
System.out.println(i);
sum = sum.add(BigInteger.valueOf(i));
}
}
System.out.println(sum);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SummationOfPrimes summationOfPrimes = new SummationOfPrimes();
summationOfPrimes.compute(2000000);
}
}
0 0
- 【Project Euler】【Problem 10】Summation of primes
- project euler problem 10:Summation of primes
- 10 Summation of primes - Project Euler
- Project Euler Problem 10: Summation of primes
- project euler 10 Summation of primes
- Project Euler 010 Summation of primes
- Problem 10:Summation of primes
- Problem 10:Summation of primes
- PE 10 Summation of primes
- Problem 10 Summation of primes
- (Problem 10)Summation of primes
- projecteuler---->problem=10----Summation of primes
- Problem 10 Summation of primes (素数和)
- summation of four primes
- 110705 Summation of Four Primes
- Summation of Four Primes - PC110705
- 10168 Summation of Four Primes
- ProjectEuler-Problem10-Summation of primes
- HDOJ 2473 Junk-Mail Filter(并查集删点)
- Windows系统安装教程
- 集合框架总结(一)
- Centos6.3 Minimal 虚拟机安装与配置
- javascript格式建议(JavaScript Style Guide)
- 10 Summation of primes - Project Euler
- 0 0
- 有N个人顺序排开参加比赛,每个人可以看到自己左右两边比自己得分少的人的分数,最少的人可以得1W的奖金,并且奖金以1w递增,赛委会让大家看到得分比自己少的人得的钱比自己少,编写程序求赛委会至少准备多少钱
- #include #import @class三者究竟该用哪个
- UVa11892 Box Game
- 深受Java程序员欢迎的10款Java IDE
- 推荐算法实战
- kruskal
- MySQL 有效的建立索引