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. mysql 基础列题

    1:emp表中查询公司总共有几个部门注意,会查询出来大量重复的,使用函数distinctselect distinct job from scott.emp; 2:查询公司工资在1000-3000之间 ...

  2. phpstorm 配置 babel 支持EcmaScript6

    1.安装nodejs 2.npm install --save-dev babel-cli 3.npm install babel-preset-es2015 --save-dev 4.phpstor ...

  3. JSBinding / FAQ & Trouble Shooting

    Q: Why javascript file extension is .javascript?A: Because Unity treats .js files as Unity script an ...

  4. Java-instanceof关键字

    一.instanceof 在编写代码过程中,如果不知道一个对象属于哪一个类,这时instanceof关键字起到决定性作用,他会以boolean(true\false)反馈结果 class A{ pub ...

  5. 简单配置和使用Maven

    1,下载Maven 从:https://maven.apache.org/download.cgi 其实两个都一样, 2,安装过程 解压你下载的包,随意放哪里都可以 ,假设 我放在了 D:\JavaT ...

  6. unity, 调节图片导入尺寸

    unity中直接导入高清图,通过max size来调节图片尺寸. 打包的时候通过看editor log或通过插件来监视是否有过大尺寸的图片.

  7. JDK、JRE、JVM

    首先来说一下JDKJDK(Java Development Kit) 是 Java 语言的软件开发工具包(SDK).JDK是整个JAVA的核心,包括了Java运行环境(Java Runtime Env ...

  8. app升级方法

    1.到那里找apk? (1)Android Studio菜单Build->Generate Signed APK     (2)弹出窗口     (3)创建密钥库及密钥,创建后会自动选择刚创建的 ...

  9. Access 数据库连接 字符串

    <!--Microsoft.Practices.EnterpriseLibrary.Data.dll 操作引用程序集--> <connectionStrings> <ad ...

  10. TObject、Pointer、Interface的转换

    unit Unit4; ));   ));   ));   //将Obj转为接口   //LInf1 := ITest(Pointer(LObj1));       //无法转换了,丢失了接口信息   ...