projecteuler Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
译文:
10以下的素数之和为17,求出2000000以下的素数之和。
=======================
第一次code:
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
long start = System.currentTimeMillis();
System.out.println(su(2000000));
long end = System.currentTimeMillis();
System.out.println(end-start);
}
/*
* 判断是否为素数
* /
static boolean sum(int n)
{
boolean isPrime=true;
int s=(int)Math.sqrt(n);
for(int i=s;i>1;i--)
{
if(n%i==0)
{
isPrime=false;
}
}
return isPrime;
}
/*
* 循环遍历素数
* 求和
*/
static long su(int n)
{
long sum=0;
for(int i=2;i<n;i++)
{
if(sum(i)== true)
{
sum += i;
}
}
return sum;
}
}
结果为142813828922,时间效率为8257毫秒。
projecteuler Summation of primes的更多相关文章
- Summation of primes
是我算法不对,还是笔记本CPU太差? 我优化了两次,还是花了三四个小时来得到结果. 在输出上加1就是最终结果. The sum of the primes below 10 is 2 + 3 + 5 ...
- (Problem 10)Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two milli ...
- Problem 10: Summation of primes
def primeslist(max): ''' 求max值以内的质数序列 ''' a = [True]*(max+1) a[0],a[1]=False,False for index in rang ...
- Python练习题 038:Project Euler 010:两百万以内所有素数之和
本题来自 Project Euler 第10题:https://projecteuler.net/problem=10 # Project Euler: Problem 10: Summation o ...
- PE 001~010
题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的 ...
- Project Euler Problem 10
Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...
- PE刷题记
PE 中文翻译 最喜欢做这种很有意思的数学题了虽然数学很垃圾 但是这个网站的提交方式好鬼畜啊qwq 1.Multiples of 3 and 5 直接枚举 2.Even Fibonacci numbe ...
- Summation of Four Primes - PC110705
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10168.html 原创:Summ ...
- UVA 10168 Summation of Four Primes(数论)
Summation of Four Primes Input: standard input Output: standard output Time Limit: 4 seconds Euler p ...
随机推荐
- 在树莓派(Raspberry Pi)上编译安装更新版本的Python
Raspiban Wheezy上预装的Python3版本是3.2.3,本文将介绍升级到3.4.3的方法. 此文也适用于安装其它版本(比如最新版本)的Python. 我用的是B+型的树莓派,装的系统是2 ...
- unity 内存中切割图片
一般的说我们切割图片是将一张图片资源切割成更小的图片资源,也就是说在资源上就进行了切割,比如ugui上的切割方法. 如果我们有一些情况比如做拼图,可能让玩家自己选择自己的生活照作为拼图的原图. 那么我 ...
- android studio 插件
引用于:http://www.zhihu.com/question/28026027 adb-idea 支持直接在AS面板中进行ADB操作,个人觉得太实用,上面有哥们已提及,这里再介绍下: Unins ...
- php excel读取
当然首先要判断是否有文件和文件类型,接着把文件保存到某个路径中 /** * 读取excel数据 * @author Red * @date * @param $filename 文件所在路径+文件名 ...
- 浏览器下载/导出文件 及jQuery表单提交
1 比如以下按钮, 用于导出文件,如EXCEL文件. <li> <button class="whiteBg btn2" onclick="doExp( ...
- Code Page 编码
Identifier .NET Name Additional information 037 IBM037 IBM EBCDIC US-Canada 437 IBM437 OEM United St ...
- 64位weblogic11g安装
oracle官网上下载的weblogic就是全功能版本,下面是下载 64bit weblogic 等待下载中…… 下载完成后运行 jar 文件(不会运行jar 的请自己百度) 运行时出现如下 原因是 ...
- 如何使用openssl生成RSA公钥和私钥对
在ubuntu上要使用openssl的话需要先进行安装,命令如下: sudo apt-get install openssl 安装完成就可以使用openssl了. 首先需要进入openssl的交互 ...
- GBDT算法原理深入解析
GBDT算法原理深入解析 标签: 机器学习 集成学习 GBM GBDT XGBoost 梯度提升(Gradient boosting)是一种用于回归.分类和排序任务的机器学习技术,属于Boosting ...
- Calendar
/* * Calendar:它为特定瞬间与一组诸如 YEAR.MONTH.DAY_OF_MONTH.HOUR 等 日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方 ...