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. DownloadProvider 源码详细分析

    DownloadProvider 简介 DownloadProvider 是Android提供的DownloadManager的增强版,亮点是支持断点下载,提供了“开始下载”,“暂停下载”,“重新下载 ...

  2. Luogu 1312 【NOIP2011】玛雅游戏 (搜索)

    Luogu 1312 [NOIP2011]玛雅游戏 (搜索) Description Mayan puzzle 是最近流行起来的一个游戏.游戏界面是一个7行5列的棋盘,上面堆放着一些方块,方块不能悬空 ...

  3. [luogu1655][小朋友的球]

    luogu1665 思路 一道第二类斯特兰数的模板题.只不过需要写个高精. f[i][j]表示前i个球放到j个盒子里的方案数.第i个球可以单独一个盒子,所以f[i][j]+=f[i-1][j-1].还 ...

  4. 源码研究:php变量

    一:php中的变量类型 1.标量类型:布尔型 bool,整型 int,浮点型 float,字符串型 string2.复杂类型:数组 array,对象 object3.特殊类型:NULL,资源 reso ...

  5. 基于 Django 2.0.4 的 djcelery 配置

    Django Celery 配置实践 所需环境 python 3.5.2 rabbitmq 安装所需的包 pip install -r requirements.txt QuickStart 创建Dj ...

  6. shell脚本递归压缩实践

    #!/bin/bash Src_Path=/data/www/logs Dst_Path=/data/www/logs_bak for rfile in `find $Src_Path/ -depth ...

  7. Kanboard简单的可视化任务板,项目管理

    采用docker安装 简单快捷 下载 docker pull kanboard/kanboard:latest 运行 docker run -d --name kanboard -p 10080:80 ...

  8. Java NIO 机制分析(一) Java IO的演进

    一.引言 Java1.4之前的早期版本,Java对I/O的支持并不完善,开发人员再开发高性能I/O程序的时候,会面临一些巨大的挑战和困难,主要有以下一些问题: (1)没有数据缓冲区,I/O性能存在问题 ...

  9. 3 快速创建SpringBoot项目

    一.Intellij IDEA 创建Spring Boot项目 1.创建工程  2.选择Spring Initializr 3.设置Maven版本管理参数  4.选择引用模块  5.命名工程名 6.选 ...

  10. golang error信息转字符串 x := fmt.Sprintf("%s", err)

    _, _, ch, err := m.ZkConn.ChildrenW(node) if err != nil { x := fmt.Sprintf("%s", err) if s ...