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. 深入ThreadLocal之三(ThreadLocal可能引起的内存泄露)

    threadlocal里面使用了一个存在弱引用的map,当释放掉threadlocal的强引用以后,map里面的value却没有被回收.而这块value永远不会被访问到了. 所以存在着内存泄露. 最好 ...

  2. gerrit 使用笔记

    添加git hooks git库的钩子目录中有一个commit-msg脚本文件,可以在git执行commit时,在提交信息中自动添加一个唯一的Change-Id scp -P 29419 admin@ ...

  3. URL编码CFURLCreateStringByAddingPercentEscapes使用(ARC)

    URL 编码:CFURLCreateStringByAddingPercentEscapes If you have tried to send any information using a GET ...

  4. Python深入05 装饰器

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 装饰器(decorator)是一种高级Python语法.装饰器可以对一个函数.方法 ...

  5. bootstrap-下拉菜单

    <!-- 1.给父级添加class为dropdown,或者给父级添加定位属性 2.给button添加data-toggle="dropdown"属性,并添加dropdown- ...

  6. Valid Number @python

    Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 ...

  7. Jmeter监控系统等资源,ServerAgent端口的修改

    默认情况下在下载的ServerAgent下,如果服务是windows系统,则直接启动"startAgent.bat"即可,如果是Linux系统,则直接启动"./start ...

  8. SQL游标 更新

    --定义游标 DECLARE cur_getaddress CURSOR FOR SELECT new_a ,new_b ,new_c ,new_d FROM table WHERE (new_a i ...

  9. Windows server 2008 下iis7 架设ftp服务器

    架设了一天的ftp服务器,终于搞定了. 按着windows server 2003的思路在windows server 2008把ftp设置好后,登录过程老是出现:530 User cannot lo ...

  10. Flex使用宋体渲染越南语显示错误

    本来应该显示Lưu nhóm,偏偏编译后显示Lưu nhòm.二声变成了四声,并且某些情况下,刚打开的窗口时二声的,然后变成了四声.初始以为是Flex的问题,分别使用S和mx包下的Label做实验,后 ...