简单:

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. Struts2初学习记录

    以下笔记内容来自尚硅谷_Struts2_佟刚老师的视频教程+自己一点点整理 来源免责声明 一. 1. VS 自实现: 1). 搭建 Struts2 的开发环境 2). 不需要显式的定义 Filter, ...

  2. [oracle安装错误处理]ORA-00600: [keltnfy-ldmInit][46], [1], []

    原博文:http://blog.itpub.net/519536/viewspace-614893/ 今天在部署一套10g Oracle(10.2.0.3版本)的过程中,偶遇ORA-00600: in ...

  3. SKCropNode类

    继承自 SKNode:UIResponder:NSObject 符合 NSCoding(SKNode) NSCopying(SKNode) NSObject(NSObject) 框架 /System/ ...

  4. TCP服务器:多进程

    代码: server: #include<netinet/in.h> #include<sys/socket.h> #include<sys/wait.h> #in ...

  5. Eclipse(MyEclipse)使用技巧——改动凝视字体大小

    Eclipse在安装完毕后,凝视的字体大小远远小于代码的大小,依照网上查的相关信息 窗体--首选项--常规--外观--颜色和字体--基本--文本字体--编辑 Window -->Preferen ...

  6. 配置Windows下编译运行C/C++过程

    1.首先确定电脑安装了VS或者VC++的IDE: 2.修改环境变量 在系统属性-高级-环境变量-用户变量中: 编辑PATH增加cl编译器的路径D:\Program Files\Microsoft Vi ...

  7. mui实现自动登录

    <!DOCTYPE html><html> <head> <meta charset="utf-8"> <meta name= ...

  8. MFC 中的 “printf” 函数

    怀念C语言的我,MFC没法使用的C语言printf函数,于是: int MFCprintf(const char* m_data, ...){ CString str; char printf_buf ...

  9. OD: File Vulnerabilities & Protocols & Fuzz

    IE.Office 等软件有个共同点,即用文件作为程序的主要输入,但攻击者往往会挑战程序员的假定和假设. 文件格式 Fuzz 就是利用畸形文件测试软件的稳健性,其流程一般包括: * 以一个正常文件作为 ...

  10. RadioGroup单选按钮排版

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...