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的更多相关文章

  1. Summation of primes

    是我算法不对,还是笔记本CPU太差? 我优化了两次,还是花了三四个小时来得到结果. 在输出上加1就是最终结果. The sum of the primes below 10 is 2 + 3 + 5 ...

  2. (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 ...

  3. Problem 10: Summation of primes

    def primeslist(max): ''' 求max值以内的质数序列 ''' a = [True]*(max+1) a[0],a[1]=False,False for index in rang ...

  4. Python练习题 038:Project Euler 010:两百万以内所有素数之和

    本题来自 Project Euler 第10题:https://projecteuler.net/problem=10 # Project Euler: Problem 10: Summation o ...

  5. PE 001~010

    题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的 ...

  6. 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 ...

  7. PE刷题记

    PE 中文翻译 最喜欢做这种很有意思的数学题了虽然数学很垃圾 但是这个网站的提交方式好鬼畜啊qwq 1.Multiples of 3 and 5 直接枚举 2.Even Fibonacci numbe ...

  8. Summation of Four Primes - PC110705

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10168.html 原创:Summ ...

  9. UVA 10168 Summation of Four Primes(数论)

    Summation of Four Primes Input: standard input Output: standard output Time Limit: 4 seconds Euler p ...

随机推荐

  1. [课程设计]Scrum团队分工及明确任务1.0 ----多鱼点餐

    [课程设计]Scrum团队分工及明确任务1.0 ----多鱼点餐 一.开发背景 多鱼点餐系统是一套比较系统化的针对餐厅点餐服务的产品,从顾客进入餐厅点餐到用餐结束再到最后的结账买单,需要全面的.高效的 ...

  2. MATLAB 绘图时的相关心得

    matlab中如何调整legend的位置? legend('sinx',-1); %----位于图形框外面-----------------------legend('sinx',0);------- ...

  3. oracle数据库从入门到精通之三

    综合案例ddl&dml有一个商品数据库1.数据表的创建    ddl先编写数据库脚本--删除数据表drop table purcase purge;drop table product pur ...

  4. geohash-net实现

    基于c#语言 geohash算法基本实现源码,参见: https://github.com/sharonjl/geohash-net , 源码中具体包含如下方法: String CalculateAd ...

  5. 创建COM对象时遭遇 800702e4

    SolidEdge st5(x64) SDK /vs2012/win8.1 x64 西夏普创建SEApplication COM对象时遭遇800702e4.翻来覆去的调vs进程的权限,调se进程的权限 ...

  6. 多线程下的 Lambda表达式 异步 WebClient 读取程序图标,来作为托盘 图标 logo ico

    //读取程序图标,来作为托盘图标this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Form ...

  7. IOS:Safari不兼容Javascript中的Date问题

    在IOS5以上版本(不包含IOS5)中的Safari浏览器能正确解释出Javascript中的 new Date('2013-10-21') 的日期对象. 但是在IOS5版本里面的Safari解释ne ...

  8. nodejs单元测试

    前言: 之前一直听说过单元测试,但是具体怎么做,也没有深入研究,感觉测试是一件很麻烦的事,花费时间.可能是自己太懒了,一看到测试那么多陌生的东西就不想弄了. 然后一拖再拖,直到最近,换了一家公司,然后 ...

  9. .NET文件跨服务器上传下载

    环境说明:两台服务器服务器为A,服务器为B,服务器B为文件服务器 1.在A和B上创建用户docshareuser,用户名和密码保持一致 2.B服务器上设置附件文件夹Attachments共享,添加用户 ...

  10. 一个奇葩的SQL

    需求 建表脚本 CREATE TABLE [dbo].[A]( ) NOT NULL, ) NULL ) ON [PRIMARY] GO CREATE TABLE [dbo].[B]( ) NOT N ...