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. Linux中记录终端(Terminal)输出到文本文件(转载)

    一,如何把命令运行的结果保存到文件当中? 这个问题太简单了,大家都知道,用 > 把输出转向就可以了 例子: [lhd@hongdi ~]$ ls > ls.txt [lhd@hongdi ...

  2. SqlServer2005基于已有表创建分区

    随着当今数据库的容量越来越快的朝着在大型数据库或超大型数据库的发展,对于数据库中的大 型表以及具有各种访问模式的表的可伸缩性和可管理性运行环境变得尤为重要, SQL server 从 SQL serv ...

  3. php 循环向<select>添加选项

    在控制器内:$this->assign('data',$data);

  4. 【译】深入理解python3.4中Asyncio库与Node.js的异步IO机制

    转载自http://xidui.github.io/2015/10/29/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3python3-4-Asyncio%E5%BA%93% ...

  5. (easy)LeetCode 204.Count Primes

    Description: Count the number of prime numbers less than a non-negative number, n. Credits:Special t ...

  6. reverse list

    public void reverse (){ Node end =null,p,q; p=head; //p代表当前节点,end代表翻转后p后面的,q代表翻转前p后面的 while(p!=null) ...

  7. iOS7 下去掉状态栏(全屏)

    具体步骤如下: 1.在项目的-Info.plist文件中,添加Row: Key:View controller-based status bar appearance Value:NO 2.选择项目在 ...

  8. java静态内部类

    public class StaticInnerClass {        int x=100;    static class inner{        void doitInner()     ...

  9. 01-Quartz2D介绍

    01-PPT介绍 *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !impo ...

  10. 举例说明划分子网,路由器IP地址

    划分子网的方法是从网络的主机号借用若干位作为子网号,主机号相应地减少了同样的位数.在划分子网前,IP地址是两级结构的:网络号,主机号. 划分子网后,两级IP地址在本单位内部就变为三级IP地址:网络号, ...