Problem 6: Sum square difference
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025Hence 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的更多相关文章
- (Problem 6)Sum square difference
Hence the difference between the sum of the squares of the first ten natural numbers and the square ...
- projecteuler Sum square difference
The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of ...
- Sum square difference
简单: e sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square o ...
- (Problem 57)Square root convergents
It is possible to show that the square root of two can be expressed as an infinite continued fractio ...
- 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 ...
- 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 ...
- [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 ...
- [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 ...
- [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 ...
随机推荐
- DataTable转实体类
/// <summary> /// DataTable与实体类互相转换 /// </summary> /// <typeparam name="T"& ...
- Tomcat性能优化(转载)
出处:微信订阅号GitChat精品课程 — Tomcat性能优化 Tomcat 简单介绍 Sun 公司创建了第一个 Servlet 容器,即 Java Web Server,但 JWS 只是为了演示 ...
- 闽南师范大学·大英A3复习专题
精读<新视野·读写教程A3> U2: words: TEXT A TEXT B appraise vt.评定 | abort vt.(因困难或危险)使(活动)终止 paralyze v ...
- python pyqt绘制直方图
# -*- coding: utf-8 -*- """ In this example we draw two different kinds of histogram. ...
- hive小文件合并设置参数
Hive的后端存储是HDFS,它对大文件的处理是非常高效的,如果合理配置文件系统的块大小,NameNode可以支持很大的数据量.但是在数据仓库中,越是上层的表其汇总程度就越高,数据量也就越小.而且这些 ...
- 【转】TCP、UDP、RTP(RTCP)区别
转自:https://www.cnblogs.com/imystr/p/4026639.html OSI七层模型OSI 中的层 功能 ...
- Java多线程概念
1 多线程 1.1 什么是进程? 应用程序的一次运行产生进程. 为什么存在进程的概念? 1.2 什么是线程 参考:https://www.cnblogs.com/geeta/p/9474051.htm ...
- vue eventBus使用
类似于iframe之间的possMessage方式传参 1.eventBus.js文件 //用于兄弟组件通信 import Vue from 'vue'; export default new Vue ...
- class类初始化之后调用赋值问题记录
class PWSTRDELL: def __init__(self, pw_str):#该方法在类实例化时会自动调用 self.pw = pw_str self.strength_level = 0 ...
- 为什么Java的main方法必须是public static void?
一. void 如下,像C, C++一样,将返回值类型改为int,再返回一个0,虽然编译通过,但是运行时会报错. 找到一种可理解的解释:方法的副作用和返回值类型.(http://www.cnblogs ...