简单:

e 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.

def naturalnumber(n):
    sumnatural = 0
    for i in xrange(1,n+1):
        sumnatural += i * i
    return sumnatural

def squarenumber(n):
    sumsquare = 0
    for i in xrange(1,n+1):
        sumsquare += i
    return sumsquare * sumsquare

print squarenumber(100) - naturalnumber(100)

C:\webpy\webpy\Scripts\python.exe C:/pycode/euler.py
25164150

Process finished with exit code 0

Sum square difference的更多相关文章

  1. projecteuler Sum square difference

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

  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. PE 001~010

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

  7. Project Euler Problem6

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

  8. PE刷题记

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

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

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

随机推荐

  1. 9月19号-9月21号丰宁坝上草原行 - 营销系统 - 京东内部论坛 - Powered by Discuz!

    9月19号-9月21号丰宁坝上草原行 - 营销系统 - 京东内部论坛 - Powered by Discuz! 9月19号-9月21号丰宁坝上草原行   [复制链接]

  2. jQuery源代码 解析一 工具方法

    1. 外层沙箱以及命名空间$ 几乎稍微有点经验前端人员都这么做,为了避免声明了一些全局变量而污染,把代码放在一个"沙箱执行",然后在暴露出命名空间(可以为API,函数,对象): 2 ...

  3. Entity Framework Code First 多数据库 控制台迁移代码

    1.启动迁移 Enable Migrations Enable-Migrations -MigrationsDirectory "MigrationsOne" -ContextTy ...

  4. ref传参时出错

    下面是一段正确的代码: //基类A public class A { public void SomeMethod(A a) { } } //派生类B public class B:A { } //在 ...

  5. vs2012加载EntityFrameWork框架,连接Oracel

    近日公司用到.net MVC框架做接口,需连接到Oracel数据库,从网上查阅了一些资料,当然,从咱们博客园获益匪浅.然后结合自己所做,把使用过程中遇到的一些问题,及如何解决的整理如下,方便查阅,也有 ...

  6. NotImplementedException未实现该方法或操作

    使用DevExpress为控件CheckedListBoxControl绑定DataSource时,引发异常“NotImplementedException未实现该方法或操作”,代码如下: this. ...

  7. Wcf资料收集

    1.简介 http://www.tuicool.com/articles/mqYB32 使用规范 http://blog.51cto.com/zt/219 2.教程系列 http://www.cnbl ...

  8. memcache和数据库的使用技巧

    1.加速无数据的访问速度毋庸置疑取数据先去取下memcache里的数据,如果没有再去数据库取数据但这样如果我取100次都是没有的那么我得去数据库去取100次 如果还是重复的...那么效率就不高了 解决 ...

  9. 记一次T-SQL查询优化 索引的重要性

    概述 在一次调优一个项目组件的性能问题时,发现SQL的设计真的是非常的重要,所以写一篇博文来记录总结一下. 环境介绍 这个项目组件是一个Window服务,内部在使用轮循机会在处理一个事件表中的事件,将 ...

  10. bash:ifconfig command not found for contos7.0

    CentOS7刚发布,我忍不住把DELL T410从CentOS6升级到CentOS7.好不容易等安装结束后,立即配置网络,然后在yum源上安装环境.可是执行ifconfig的时候系统提示让我傻了眼: ...