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 ...
随机推荐
- UCOS-信号标志组(学习笔记)
信号标志组即根据各任务的信号进行逻辑运算,根据逻辑运算的结果决定是否进行.发送方指定向那个标志组的哪一位(响应位等于1表明向哪一位发)发1还是0.等待逻辑结果的任务指定等待那个标志组的哪几位.这几位按 ...
- Laravel5.0 CSRFチェックを無効化(修改后可以像5.1以上那样从CSRF保护中排除指定URL)
Laravel5では全てのPOSTに勝手にCSRFチェックが付いてきます.便利と言えば便利ですが.Laravel外からのPOSTを受け取りたいときなど大迷惑です. CSRFチェックを排除する方法が何故 ...
- Java链式方法 连贯接口(fluent interface)
有两种情况可运用链式方法: 第一种 除最后一个方法外,每个方法都返回一个对象 object2 = object1.method1(); object3 = object2.method2(); ob ...
- VVDocumenter-Xcode 规范注释生成器 插件之安装调试适应新版本
1.下载地址: 很多时候,为了快速开发,很多的技术文档都是能省则省,这个时候注释就变得异常重要,再配合Doxygen这种注释自动生成文档的,就完美了.但是每次都要手动输入规范化的注释,着实也麻烦,但有 ...
- R中将list类型数据转换成data.frame型
例如将如下数据转换成data.frame型: l <- replicate( 5, list(sample(letters, 4)), simplify = FALSE ) => 用unl ...
- centos7安装mysql
centos7安装mysql 1 查找系统是否安装了myql rpm -q mysql mysql-server1.1如果安装了.就删除 sudo yum -y remove mysql mysql- ...
- 表空间、Schema和用户
源地址:http://www.cnblogs.com/kevinanni/p/3688921.html
- 破解ckfinder2.3 去除版本号和标题提示
1.找到ckfinder.js 2.找到这样的字符串 <h4 class='message_content'></h4> 3.改成这样 <h4 style='displa ...
- 基于nginx和uWSGI在Ubuntu上部署Djan
http://www.jianshu.com/p/e6ff4a28ab5a 文/Gevin(简书作者)原文链接:http://www.jianshu.com/p/e6ff4a28ab5a著作权归作者所 ...
- FreeMarker中List排序
有时候需要在页面上对list排序,虽然也可以在后台代码中完成,但这个可能要看具体情况.排序的样本代码如下: <#list resultMap.topViewList?sort_by(" ...