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 ...
随机推荐
- JAVA 99乘法表实例
实例: public class Test{ public static void main(String[] args){ for(int i=1;i<=9;i++){ for(int j=1 ...
- ubuntu网络配置相关知识(转载)
From:http://os.51cto.com/art/201003/188055.htm 文章主要介绍Ubuntu网络配置,希望能让Linux新手学习参考.更好使用Ubuntu.更有效的学习Ubu ...
- [ActionScript 3.0] AS3调用百度地图API
package { import baidu.map.basetype.LngLat; import baidu.map.basetype.Size; import baidu.map.config. ...
- Dubbo Multicast 注册中心即相关代码实现
Dubbo 的 Multicast注册中心有下面特点: 不需要启动任何中心节点,只要广播地址一样,就可以互相发现 组播受网络结构限制,只适合小规模应用或开发阶段使用. 组播地址段: 224.0.0.0 ...
- Java内存区域分配基恩内存溢出异常
- OpenStack学习
========================================== openstack的场景是什么 openstack的目的是把空闲的机器组织起来,经过虚拟化,租给用户使用. 出现的 ...
- jdk线程的简单使用
一.线程的实现方式方式一:继承Thread类一个类只要继承了Thread类,并重写run()方法,则就可以实现多线程的操作. public class ThreadDemo01 { public st ...
- js对象2--工厂模式的由来--杂志
一:工厂模式引入前提例子 先看一个案例 <script type="text/javascript"> var person= new Object(); //创建一个 ...
- [ CodeVS冲杯之路 ] P1368
不充钱,你怎么AC? 题目:http://codevs.cn/problem/1368/ 嗯……泡泡堂,很劲啊,其实就是个盗版的田忌赛马 http://www.cnblogs.com/hyfer/p/ ...
- 在Service Fabric上部署Java应用,体验一把微服务的自动切换
虽然Service Fabric的Java支持版本还没有正式发布,但是Service Fabric本身的服务管理.部署.升级等功能是非常好用的,那么Java的开发者可以如何利用上Service Fab ...