Sum square difference

Problem 6

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.

Quite simple , the code is as follows:

def getSumOfSquare(began,end):
sum = 0
for i in range(began, end+1):
sum += pow(i, 2)
return sum def getSquareOfSum(began, end):
sum = 0
for i in range(began, end+1):
sum += i
sum = pow(sum, 2)
return sum print(getSumOfSquare(1, 100))
print(getSquareOfSum(1, 100))
print(getSquareOfSum(1, 100)-getSumOfSquare(1, 100))

  

Project Euler Problem6的更多相关文章

  1. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  2. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  3. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  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. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  6. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

  7. Project Euler 第一题效率分析

    Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...

  8. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

  9. Python练习题 048:Project Euler 021:10000以内所有亲和数之和

    本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...

随机推荐

  1. Android微信数据导出

    在Nexus 5(Android 4.4)+WeChat 5.4,和Nexus 5(Android 5.0)+Wechat 6.0上测试可用. 获取加密的sqlite3数据库EnMicroMsg.db ...

  2. DOM表单(复选框)

    在表单中,尤为重要的一个属性是name <!--复选框的全选.全不选.反选--> <!DOCTYPE> <html> <head lang="en& ...

  3. 无法SSH服务器的解决过程(openssh-daemon is stopped)

    公司某台服务器不知为何无法ssh连接上,进入现场查看: 1.执行netstat -atnlp|grep ssh,没有找到ssh端口 2.执行ps aux|grep ssh,没找到相关进程 3.执行se ...

  4. Arcgis api 离线部署

    Arcgis api 离线部署 修改 文件一(init.js)位置:arcgis_js_v317_api\arcgis_js_api\library\3.17\3.17\init.js 将[HOSTN ...

  5. Django 日志配置按日期滚动

    记录下Django关于日期的配置,以及如何根据日期滚动切割日志的问题. 配置的源码在githun上 https://github.com/blackmatrix7/django-examples/tr ...

  6. 移动端自动化测试-Windows-Android-Appium环境搭建

    1.安装JDK,并且配置好[JAVA_HOME]和[path]两个环境变量 1.1.JAVA_HOME:指向JDK的安装路径(如:C:\Program Files (x86)\Java\jdk1.7. ...

  7. CodeForces842C 树上dfs

    http://codeforces.com/problemset/problem/842/C 题意: 有一个n个节点的数,每个点有一个点权,根到这个点的所有点权(包括这个点和根)的gcd值为这个点的答 ...

  8. HDFS集群PB级数据迁移方案-DistCp生产环境实操篇

    HDFS集群PB级数据迁移方案-DistCp生产环境实操篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 用了接近2个星期的时间,终于把公司的需要的大数据组建部署完毕了,当然,在部 ...

  9. Git-Credential-Manager-for-Mac-and-Linux

    1.安装brew 安装命令: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/instal ...

  10. MySQL开启远程连接的方法

    默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件. 一.修改/etc/mysql/my.conf找到bind-address = 127.0 ...