Problem 6: Sum square difference

时间:2022-09-28 07:56:23

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.

这第六题python实现最简单吧

max1 = 100

sum1 = 0
sum2 = 0
for i in range(1,max1+1):
sum1 += i**2 sum2 = ((1+max1)*max1/2)**2
print(sum2-sum1)

  

Problem 6: Sum square difference的更多相关文章

  1. (Problem 6)Sum square difference

    Hence the difference between the sum of the squares of the first ten natural numbers and the square ...

  2. projecteuler Sum square difference

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

  3. Sum square difference

    简单: e sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square o ...

  4. (Problem 57)Square root convergents

    It is possible to show that the square root of two can be expressed as an infinite continued fractio ...

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

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

  7. [LeetCode&Python] Problem 404. Sum of Left Leaves

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...

  8. [LeetCode&Python] Problem 530. Minimum Absolute Difference in BST

    Given a binary search tree with non-negative values, find the minimum absolute difference between va ...

  9. [LeetCode&Python] Problem 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

随机推荐

  1. 搞懂$.each和$(selector).each

    $.each:该方法用于遍历任何集合,包括数组和对象 $(selector).each:该方法用于遍历Jquery对象 语法:$.each(obj,callback,args) ①遍历数组 var a ...

  2. 关于Kb/s,KB/s的一些知识

    我们常见的有KB/s和Kb/s两种 1,Kb/s也就是Kbps.这里面小写的b是bit(比特)的缩写,是位的意思.一个位就是二进制的0或者1.一般代表传输单位,p就是/号,s是秒.bps就是b/s=比 ...

  3. struts2标签之列求和

    struts2标签之列求和 <table width="100%" border="0" cellpadding="0" cellsp ...

  4. win7 通过命令行压缩文件

    1,下载winrar这款软件(可能要正式版) 2,安装完之后在c:\programe files里找到winrar目录,复制winrar目录里的winRar.exe文件到c盘下的windows目录 3 ...

  5. 基于Asp&period;Net Core Mvc和EntityFramework Core 的实战入门教程系列-3

    来个目录吧: 第一章 第二章 第三章 暂时就这么多.后面路线更新吧 创建.查询.更新.删除 这章主要讲解使用EF完成 增删改查的功能. 自定义"详情信息"页面 我们通过基架生成的代 ...

  6. APMServ中的 Apache无法启动…

    情况1. 找问题:C:\APMServ5.2.6\Apache\bin点击httpd.exe 会出现: path is invalid.(地址无效) 解决办法:找到C:/APMServ5.2.6/Ap ...

  7. SQL Server学习之路(二):主键和外键

    0.目录 1.定义 1.1 什么是主键和外键 1.2 主键和外键的作用 1.3 主键.外键和索引的区别 2.主键(primary key) 2.1 通过SSMS设置主键 2.2 通过SQL语句设置主键 ...

  8. SQLMap入门之在Windows上安装SQLMap

    前言: SQLMap是一个开放源代码的sql注入工具,SQLMap是使用Python语言开发成的,他的运行需要有Python环境的支持.写这篇文章时我使用的SQLMap版本是"sqlmap- ...

  9. github&lowbar;地址

    网络请求: hongyangAndroid/okhttputils(包含cookie的管理): 图片之压缩: Sunzxyong/Tiny:(http://www.tuicool.com/articl ...

  10. python start

    由于工作关系,新学习使用了python,感觉能非常快速和方便的开发,看完<简明 Python 教程>就跃跃欲试,实际用的是发现有些和C#的理解不一样 (1)如何筛选元组 例如  recor ...