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 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.
# Answer: 25164150 x = y = 0
for i in range(1, 101):
x += i
y += i**2
print(x**2 - y)
这题纯粹是送分题,就是简单的加减法和乘方计算。应该没啥算法可言吧。。。
Python练习题 034:Project Euler 006:和平方与平方和之差的更多相关文章
- Python练习题 032:Project Euler 004:最大的回文积
本题来自 Project Euler 第4题:https://projecteuler.net/problem=4 # Project Euler: Problem 4: Largest palind ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- Python练习题 046:Project Euler 019:每月1日是星期天
本题来自 Project Euler 第19题:https://projecteuler.net/problem=19 ''' How many Sundays fell on the first o ...
- Python练习题 039:Project Euler 011:网格中4个数字的最大乘积
本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...
- Python练习题 033:Project Euler 005:最小公倍数
本题来自 Project Euler 第5题:https://projecteuler.net/problem=5 # Project Euler: Problem 5: Smallest multi ...
- Python练习题 049:Project Euler 022:姓名分值
本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...
- Python练习题 048:Project Euler 021:10000以内所有亲和数之和
本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...
- Python练习题 047:Project Euler 020:阶乘结果各数字之和
本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial ...
- Python练习题 045:Project Euler 017:数字英文表达的字符数累加
本题来自 Project Euler 第17题:https://projecteuler.net/problem=17 ''' Project Euler 17: Number letter coun ...
随机推荐
- Xposed+X5使用
1.Xposed 2.X5
- 焦大:seo如何快速理解谷歌PR的计算奥秘
http://www.wocaoseo.com/thread-248-1-1.html 前不久看到一个搞笑的说法,有人问谷歌PR的计算是PR值=0.15+0.85*(A网页传递值+B网页传递值--), ...
- JS - 对金额数字实现千分位格式化处理
添加千分位处理: function fmoney(s, n) { n = n > 0 && n < = 20 ? n : 2; s = parseFloat((s + &q ...
- .Net Task 异步执行不等待结果返回
该文章适合有一定异步编程基础的童鞋 开始之前先看.NET官网的一张图: 异步编程中最需弄清的是控制流是如何从方法移动到方法的. 没有理解的话可以去看一下 https://docs.microsoft. ...
- 【Android】在开发项目的时候,利用AndroidStudio开发工具,突然一直报错。
作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985, QQ986945193 公众号:程序员小冰 首先说明,虽然报错,但是并不影响开发使用.但是感觉很不爽 ...
- iOS 64位静态链接库
https://www.jianshu.com/p/486e3b737707 https://stackoverflow.com/questions/44635297/setting-an-ios-s ...
- The Unique MST(最小生成树的唯一性判断)
Given a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spann ...
- ACboy needs your help (动态规划背包)
ACboy has N courses this term, and he plans to spend at most M days on study.Of course,the profit he ...
- Mybatis联合查询(一)
Mybatis的简单联合查询操作: 实体类: Employee: package com.test.mybatis; public class Employee { private Integer i ...
- 原生JDK网络编程- Buffer
Buffer用于和NIO通道进行交互.数据是从通道读入缓冲区,从缓冲区写入到通道中的.以写为例,应用程序都是将数据写入缓冲,再通过通道把缓冲的数据发送出去,读也是一样,数据总是先从通道读到缓冲,应用程 ...