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 -- 面试 -- 数据库升级策略

    升级:重写onUpgrade方法 确定 相邻版本 的差别,从版本1开始依次迭代更新,先执行v1到v2,再v2到v3…… 为 每个版本 确定与现在数据库的差别,为每个case撰写专门的升级代码. 降级 ...

  2. sqlite 日期型 字符串转为日期型

    因为sqlite为弱引用,使用字段前将他强制转为日期型,用datetime.或者最原始的 strftime. SELECT distinct ID from testTable where datet ...

  3. CF986C AND Graph

    半年前做的一道题现在还是不会 x&y=0 意味着,x的补集的子集都是和x直接相连的 不妨令图中的点数就是2^n 那么可以直接从x^((1<<n)-1)开始记忆化爆搜,路上遇到的都是 ...

  4. 【洛谷P4513】小白逛公园

    题目大意:维护动态带修改最大子段和. 题解:线段树额外维护合并最优解时需要的信息. 代码如下 #include <bits/stdc++.h> using namespace std; c ...

  5. 【模板】倍增+Floyd

    题目大意:给定一个 N 个顶点的邻接矩阵.起点顶点.终点顶点,求至少经过 K 条边(边可以重复)从起点到终点的最短路长度,若不能到达,输出 -1. 题解:至少经过 K 条边和恰好经过 K 条边的初始条 ...

  6. Apache的ProxyPass简单使用

    转: Apache的ProxyPass简单使用 置顶 2017年08月14日 18:54:33 师太,老衲把持不住了 阅读数:11164   http://mtnt2008.iteye.com/blo ...

  7. LINUX_正则表达式

    『正规表示法与通配符是完全不一样的东西!』这很重要喔!因为『通配符 (wildcard) 代表癿是 bash 操作接口癿一个功能』,但正觃表示法则是一种字符串处理癿表示方式  . (小数点):代表『 ...

  8. OS + CentOS 7 / centos 7 / config / configuration / rescue / rc.local / yum

    s centos7开启网卡功能 https://blog.csdn.net/nkd50000/article/details/78903479 网卡默认是关闭的,未分配ip地址,解决办法: 1.修改文 ...

  9. Linux 文件管理权限

    这里呢我们需要掌握的是两个命令 chmod 和 chgrp和chown 视频地址:http://www.tudou.com/listplay/pA16IH7T_Sc/LuyHbR_7Yp0.html ...

  10. 解决vue <router-link>在IE与火狐上点击失效(路由不跳转)问题

    <router-link to="/GoAbroad"> </router-link> vue中的<router-link>这种声明式的路由方式 ...