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. Django中Form的Textarea字段

    开始以为是这个样子: class BlogForm(forms.Form): title    = forms.CharField(required = True) content  = forms. ...

  2. docker存储结构解析

    由于aufs并未并入内核,故而目前只有Ubuntu系统上能够使用aufs作为docker的存储引擎,而其他系统上使用lvm thin provisioning(overlayfs是一个和aufs类似的 ...

  3. Mybatis原理分析之二:框架整体设计

    1.引言 本文主要讲解Mybatis的整体程序设计,理清楚框架的主要脉络.后面文章我们再详细讲解各个组件. 2.整体设计 2.1 总体流程 (1)加载配置并初始化       触发条件:加载配置文件 ...

  4. 在Ubuntu14.04系统POWER8服务器上搭建Docker Registry服务

    本文描述了如何在POWER8服务器上搭建一个本地化的Docker镜像仓库,主要涉及镜像制作,Docker Registry服务启动等.希望能够对在非X86服务器上搭建Docker仓库的同学提供参考. ...

  5. 【总结】总结写了3个React页面后遇到的各种坑

    标签里用到<label for>的,for 要写成htmlFor 标签里的class要写成className 组件首字母一定要大写 单标签最后一定要闭合 如果html里要空格转义, 注意不 ...

  6. 【学】jQuery的源码思路4——增加一些功能

    本文说一些简单的jQuery实现原理 eq() get() hide() show() index() find() //返回找到的一组元素中的第n个 zQuery.prototype.eq=func ...

  7. ios中图片拉伸用法

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCap ...

  8. Nginx图片剪裁模块探究

    http://nginx.org/en/docs/http/ngx_http_image_filter_module.html http://cwtea.blog.51cto.com/4500217/ ...

  9. java 绘图

    java 绘图 圆形.线条.矩形.填充 插入图片 文字 //绘图 import java.awt.*; import javax.swing.*; public class Index extends ...

  10. JVM实用参数(四)内存调优

    理想的情况下,一个Java程序使用JVM的默认设置也可以运行得很好,所以一般来说,没有必要设置任何JVM参数.然而,由于一些性能问题(很不幸的是,这些问题经常出现),一些相关的JVM参数知识会是我们工 ...