首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Problem 十

2012-11-03 
Problem 10问题描述:The sum of the primes below 10 is 2 + 3 + 5 + 7 17.Find the sum of all the pri

Problem 10
问题描述:
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.



public static boolean IsPrime(long number) {int begin = 2;int end = (int) Math.sqrt(number) + 1;for (int i = begin; i < end; i++) {if (number % i == 0)return false;}return true;}public static long sum(){long result = 0;int begin = 2;int end = 2000000;for(int i=begin; i<end; i++){if(IsPrime(i)){result += i;}}return result;}

热点排行