简单:

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. 获取机器本地的公网ip地址

    1. ipecho.net/plain

  2. 一个简单的JUnit项目

    本人一直很喜欢JAVA,可是真正接触到JUnit也不过半年.由于公司进行网页测试,采用的是 JUnit+selenium的方式搭建的测试框架,然后采用JAVA语言编写,所以本人也好好研究了一下JUni ...

  3. Java程序员的日常—— 垃圾回收中引用类型的作用

    在Java里面,是不需要太过于关乎垃圾回收,但是这并不意味着开发者可以不了解垃圾回收的机制,况且在java中内存泄露也是家常便饭的事情.因此了解垃圾回收的相关知识就显得很重要了. 引用,在垃圾回收中是 ...

  4. redis在Java web项目的简单应用(转载)

    看到一篇关于redis和spring集成的文章,实际测试后,可以.转载以备用.谢谢 亲昵YY! html,body { font-size: 15px } body { font-family: He ...

  5. javascript动态改变当前页面中元素的状态行为

    function Datea() { var timed = document.getElementById('timed'); var t = setInterval(function TDate( ...

  6. Cadence 电源完整性仿真实践(一)

    软件版本号:Cadence 16.5 使用工具:Allegro PCB PI Option XL Power Integrity 使用资源:仿真实例下载地址:http://download.csdn. ...

  7. Java设计模式---装饰模式

    装饰模式又名包装(Wrapper)模式.装饰模式以对客户端透明的方式扩展对象的功能,是继承关系的一个替代方案. 装饰模式的结构 装饰模式以对客户透明的方式动态地给一个对象附加上更多的责任.换言之,客户 ...

  8. Python基础----函数

    1.作用域: 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. if 1==1: name = 'wupeiqi' print name 下面的结论对吗? 外层变量,可以被内 ...

  9. 小学生之使用Mybatis反向生成dao,entity,xml

    本小学生刚进公司的时候,就一顿装逼,不管别人问我啥我都会说:"会"!毕竟在公司吗,什么都要装,不要别人看出你的底细.不过有一天,听说用Mybatis可以反向生成dao(第一次听说) ...

  10. MVC4建立DBContext的EF6数据

    MVC4建立DBContext的EF6数据时 1.需要using System.Data.Entity;命名空间 2.此命名空间需要安装EntityFromwork.dll,此dll可以在项目——&g ...