The sum of the squares of the first ten natural numbers is,

12 + 22 + ... + 102 = 385

The square of the sum of the first ten natural numbers is,

(1 + 2 + ... + 10)2 = 552 = 3025

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

译文:

自然数1到10的平方之和为385,他们的和的平方为3025,现将自然数1到10的和的平方减去平方之和等于2640,求出自然数从1到100的和的平方减去平方之和。

================================

第一次code:


 public class Main
 {
     public static void main(String[] args)
     {
         System.out.println(start(100)-run(100));
     }
     /**
      * 求前N项平方之和
      * @param n
      * @return
      */
     public static int run(int n)
     {
         int m=0;
         for(int i=0;i<n+1;i++)
         {
             m += i*i;
         }
         return m;
     }
     /**
      * 求前N项和的平方
      * @param n
      * @return
      */
     public static int start(int n)
     {
         int m=0,o=0;
         for(int i=0;i<n+1;i++)
         {
             m += i;
         }
         o = m*m;
         return o;
     }
 }


projecteuler Sum square difference的更多相关文章

  1. Sum square difference

    简单: e sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square o ...

  2. (Problem 6)Sum square difference

    Hence the difference between the sum of the squares of the first ten natural numbers and the square ...

  3. Problem 6: Sum square difference

    The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of ...

  4. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  5. Porject Euler Problem 6-Sum square difference

    我的做法就是暴力,1+...+n 用前n项和公式就行 1^2+2^2+....+n^2就暴力了 做完后在讨论版发现两个有趣的东西. 一个是 (1+2+3+...+n)^2=(1^3)+(2^3)+(3 ...

  6. Python练习题 034:Project Euler 006:和平方与平方和之差

    本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square dif ...

  7. PE 001~010

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

  8. Project Euler Problem6

    Sum square difference Problem 6 The sum of the squares of the first ten natural numbers is, 12 + 22  ...

  9. PE刷题记

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

随机推荐

  1. Android系统onKeyDown监控/拦截/监听/屏蔽返回键、菜单键和Home键

    在Android系统中用来显示界面的组件(Component)为Activity,也就是说只有重写Activity的onKeyDown方法来监控/拦截/屏蔽系统的返回键(back).菜单键(Menu) ...

  2. Mac下配置JAVA_HOME

    http://blog.csdn.net/shallowgrave/article/details/39367119 闲来无事,装个Hbase玩玩,突然发现Mac下默认安装的JDK7,没有配置JAVA ...

  3. Tomcat的8009端口AJP的利用

    Tomcat在安装的时候会有下面的界面,我们通常部署war,用的最多的是默认的8080端口. 可是当8080端口被防火墙封闭的时候,是否还有办法利用呢? 答案是可以的,可以通过AJP的8009端口,下 ...

  4. ruby 字符串学习笔记1

    1 从一种数据结构中构件字符串 hash = { key1: "val1", key2: "val2" } string = "" hash ...

  5. loadrunner破解

    如果报的violation的错误,就下载hp.lr即deletelicense.exe软件运行即可以清楚注册表,然后再用管理员运行loadrunner再注册就可以了.

  6. Dede cms文章内容管理系统安全漏洞!如何有效防止DEDE织梦系统被挂木马安全设置

    第一.安装Dede的时候数据库的表前缀,最好改一下,不要用dedecms默认的前缀dede_,可以改成ljs_,随便一个无规律的.难猜到的前缀即可. 第二.后台登录一定要开启验证码功能,将默认管理员a ...

  7. 倍增法lca

    ][N],siz[N];//rt数组需要在dfs之前置-1. void dfs(int pos,int deep){ dep[pos]=deep; siz[pos]=; for(edge *it=ad ...

  8. 百度之星IP聚合(水题map&字符处理)

    虽然题目停水的,但是好像字符处理运用的还比较合适 Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊 ...

  9. ZooKeeper3.4.6配置

    添加环境变量 #ZooKeeper VARIABLES START export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.6 export PATH=$PATH ...

  10. (转)C#序列化和反序列化小例子

    网友关于序列化和反序列化的总结: ①序列化基本是指把一个对象保存到文件或流中,比如可以把文件序列化以保存到Xml中,或一个磁盘文件中 ②序列化以某种存储形式使自定义对象持久化: ③将对象从一个地方传递 ...