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 ...
随机推荐
- [ActionScript 3.0] AS3 用于拖动对象时跟随鼠标的缓动效果
package com.fylibs.components.effects { import flash.display.DisplayObject; import flash.events.Even ...
- 写代码的自动提示是怎么出来的...我的WebStorm中不能自动提示Bootstrap中的样式呢
首先开启自动提示 File -> Settings ->Editor ->Code Completion ->Preselect the first suggestion:,将 ...
- flexbox弹性盒模型
div { display:flex; } div a{ }
- delphi 调用百度地图WEBSERVICE转换GPS坐标 转
http://www.cnblogs.com/happyhills/p/3789864.html 百度地图的API说明 使用方法 第一步,申请密钥(ak),作为访问服务的依据: 第二步,按照请求参 ...
- jsp页面
//获取根目录 ${pageContext.request.contextPath} //(父页面提交,嵌入页面显示)提交表单,设置响应方法和返回结果页面显示在frame中 <input typ ...
- C# OpenFileDialog
OpenFileDialog 用于浏览并打开文件,在Windows Forms中使用,表现为标准的Windows对话框. 实例: 1.新建Windows Form Application 2.添加Op ...
- Web前端面试常识
大四校招即将席卷而来,现在临时抱抱佛脚,百度一下大概可能会问到的知识点,愿与君共勉吧! 1.Doctype(html4) A.strict 严格版本 B.transitional 过渡版本(防止 ...
- ORACLE 导空表结构
exp username/psd@sid file='E:\xx.dmp' tables=(xxx_%) ROWS=N 以下代码没什么用,我就乱写 set oracle_sid=ora11gsqlpl ...
- math对象和date对象
math对象的函数方法,记住Math首字母要大写 console.log(Math.abs(-5)); //取绝对值 console.log(Math.ceil(1.1)); //向上取舍 conso ...
- java.lang.NoSuchMethodException
这个异常遇到过若干次,提示信息也比较清楚的指示出它的特点,当无法找到某一特定方法时,就会抛出该异常! 我所遇到的抛出此异常的情景主要有以下两种: 1:对应的JAVA类中没有对应的属性,也就是说在页面的 ...