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. GC 源码分析

    java对象的内存分配入口 Hotspot 源码解析(9) •内存代管理器TenuredGeneration对垃圾对象的回收2015-01-18阅读1154 •内存代管理器DefNewGenerati ...

  2. unity panel删除drawcall失败导致的残留影像

    ngui panel 被隐藏或者删除的时候调用ondisable,清空drawcall,如果这个操作是在ontriggerenter等物理操作中就会删除不掉导致留下残影 解决方式 : 讲这些操转移到协 ...

  3. windows环境下搭建react native环境

    一.基础软件1.安装jdk-1.8.0_922.安装android studio-2.1.2(文件大小为1.2G的那个)3.安装node.js(目前最新是6.3.0)4.安装git-2.9.05.安装 ...

  4. SQL Server Profiler

    一.SQL Profiler工具简介 SQL Profiler是一个图形界面和一组系统存储过程,其作用如下: 图形化监视SQL Server查询: 在后台收集查询信息: 分析性能: 诊断像死锁之类的问 ...

  5. requests 快速入门

     requests的请求方式 import requests # 发送请求 r = requests.get('https://github.com/timeline.json') r = reque ...

  6. 关于FPGA学习路线

    1.参考FPGA厂商的参考资料,将某系列FPGA所有芯片资料下载下来,有针对性的做参考. 2.参考FPGA厂商开发板以及相应的参考设计,在开发板里有众多的外围接口电路,基本涵盖了常用的应用场合.同时也 ...

  7. MyBatis的动态SQL详解

    MyBatis的动态SQL是基于OGNL表达式的,它可以帮助我们方便的在SQL语句中实现某些逻辑,本文详解mybatis的动态sql,需要的朋友可以参考下 MyBatis 的一个强大的特性之一通常是它 ...

  8. 【学】jQuery的源码思路1——后代选择器

    jQuery的源码思路1--后代选择器 这里探讨一下jQuery中后代选择器的封装原理,并自己写一下 getEle('#div1 ul li .box');接受的参数就是个后代选择器,类似于这样: # ...

  9. OAF_开发系列24_实现OAF更新记录显示Record History(案例)

    20150716 Created By BaoXinjian

  10. easyUI+mvc权限管理后台

    通过按钮和菜单,组合成基本的功能,菜单的功能可以编码修改,但浏览功能是菜单基本的入口,只有角色赋予了浏览功能,才能访问. 基本按钮表 菜单模块 菜单分配按钮 角色授权 下面是对一张表的基本操作 模型 ...