projecteuler Sum square difference
The sum of the squares of the first ten natural numbers is,
The square of the sum of the first ten natural numbers is,
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.
译文:
自然数1到10的平方之和为385,他们的和的平方为3025,现将自然数1到10的和的平方减去平方之和等于2640,求出自然数从1到100的和的平方减去平方之和。
================================
第一次code:
public class Main { public static void main(String[] args) { System.out.println(start(100)-run(100)); } /** * 求前N项平方之和 * @param n * @return */ public static int run(int n) { int m=0; for(int i=0;i<n+1;i++) { m += i*i; } return m; } /** * 求前N项和的平方 * @param n * @return */ public static int start(int n) { int m=0,o=0; for(int i=0;i<n+1;i++) { m += i; } o = m*m; return o; } }
projecteuler Sum square difference的更多相关文章
- Sum square difference
简单: e sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square o ...
- (Problem 6)Sum square difference
Hence the difference between the sum of the squares of the first ten natural numbers and the square ...
- Problem 6: Sum square difference
The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of ...
- 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 ...
- Python练习题 034:Project Euler 006:和平方与平方和之差
本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square dif ...
- PE 001~010
题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的 ...
- Project Euler Problem6
Sum square difference Problem 6 The sum of the squares of the first ten natural numbers is, 12 + 22 ...
- PE刷题记
PE 中文翻译 最喜欢做这种很有意思的数学题了虽然数学很垃圾 但是这个网站的提交方式好鬼畜啊qwq 1.Multiples of 3 and 5 直接枚举 2.Even Fibonacci numbe ...
随机推荐
- jQuery实现的美观的倒计时实例代码
<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name=&q ...
- CentOS 6.5 更新163源(转载)
From:http://www.cnblogs.com/buffer/p/3426908.html 众所周知,Centos 有个很方便的软件安装工具 yum,但是默认安装完centos,系统里使用的 ...
- bootstrap-按钮样式
<div class="container"> <!-- 按钮的背景色 --> <div class="row"> < ...
- [ActionScript 3.0] AS3 3D双圆环贴图
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.MovieCl ...
- Java是传值还是传引用
http://www.bccn.net/Article/kfyy/java/jszl/200601/3069.html 对于基本数据类型(整型.浮点型.字符型.布尔型等),传值;对于引用类型(对象.数 ...
- systemstate dump 介绍
systemstate dump 介绍 By Janezhang-Oracle on 十二月 13, 2012 当数据库出现严重的性能问题或者hang了的时候,我们非常需要通过systemstate ...
- python3 pickle, json
pickle 有dump ,dumps ,load,loads等方法.区别在于dumps不会写入到文件. import pickle string = ['a', 2341, 'adsf'] p_st ...
- java中好玩的案例
1:实现猜数字游戏, 如果没有猜对可以继续输入你猜的数字,如果猜对了停止程序. 最多只能猜三次,如果还剩下最后一次机会的时候要提醒用户. 代码: Random random = new Random( ...
- Flex4 中<s:Datagrid>、<mx:Datagrid>添加超链接的完整方法
<s:Datagrid>的添加超链接方法(链接文字会重叠) <s:GridColumn dataField="_fileName" headerText=&quo ...
- 华为OJ平台——超长正整数相加
题目描述: 请设计一个算法完成两个超长正整数的加法. 输入 输入两个字符串数字 输出 输出相加后的结果,string型 样例输入 99999999999999999999999999999999999 ...