Sum square difference

简单:

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,布布扣,bubuko.com

时间: 2024-10-12 20:32:55

Sum square difference的相关文章

PE-6 Sum square difference

package main import "fmt" func main() { sum := 0 sum2 := 0 for i := 1; i <= 100; i++ { sum += i sum2 += i * i } fmt.Println(sum*sum - sum2) } 结果:25164150 原文地址:https://www.cnblogs.com/miria-486/p/10092986.html

projecteuler----&gt;problem=6----Sum square difference

title: 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

Square Difference

Alice has a lovely piece of cloth. It has the shape of a square with a side of length aa centimeters. Bob also wants such piece of cloth. He would prefer a squarewith a side of length bb centimeters (where b<ab<a). Alice wanted to make Bob happy, so

PE 001~010

题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的偶数求和. 003(Largest prime factor):求600 851 475 143的最大质因数. 004(Largest palindrome product):求由两个三位数相乘得到的最大回文数. 005(Smallest multiple):求能被1~20中所有数整除的最小正整数.

Python练习题 034:Project Euler 006:和平方与平方和之差

本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square difference # The sum of the squares of the first ten natural numbers is, # 1**2 + 2**2 + ... + 10**2 = 385 # The square of the sum of the first ten natur

Project-Euler problem 1-50

最近闲的做了下Project Euler 上的题目,前面50题都比较简单,简单总结下.代码一般是Python和C/C++的 用Python 做这些题目简直是酸爽啊 一下代码可能不一定是我的,因为不知道论坛里面的回复不是永久的,所以我的代码有的丢了,可能找个和我的意思相近的代码.题目翻译是从 欧拉计划 | Project Euler 中文翻译站上面Copy 的表告我. Problem 1  Multiples of 3 and 5 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是

jQuery -&gt; 获取/设置/删除DOM元素的属性

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

006:欧拉项目平方和与和的平方的差

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

欧拉计划(python) problem 6

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