Java进阶之欧拉工程 第六篇【持续更新】
2014-08-15 12:55
316 查看
原题如下:
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 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.
翻译:
前10个自然数的平方和为385,前十个自然数的和平方为3025,它们的差值为3025-385=2640,要求前一百个自然数的和平方与平方和的差值,这道题就很简单了,代码如下
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 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.
翻译:
前10个自然数的平方和为385,前十个自然数的和平方为3025,它们的差值为3025-385=2640,要求前一百个自然数的和平方与平方和的差值,这道题就很简单了,代码如下
public class Launcher { public static void main(String[] args) { int num1=0,num2=0; for(int i =1;i<101;i++){ num1=(int) (num1+Math.pow(i,2)); num2+=i; } int answer=(int) (Math.pow(num2,2)-num1); System.out.println(answer); } }
相关文章推荐
- Java进阶之欧拉工程 第四篇【持续更新】
- Java进阶之欧拉工程 第八篇【持续更新】
- Java进阶之欧拉工程 第五篇【持续更新】
- Java进阶之欧拉工程 第三篇【持续更新】
- Java进阶之欧拉工程 第二篇【持续更新】
- Java进阶之欧拉工程 第九篇【持续更新】
- Java进阶之欧拉工程 第十篇【持续更新】
- Java进阶之欧拉工程 第十一篇【持续更新】
- Java进阶之欧拉工程 第七篇【持续更新】
- Java进阶之欧拉工程 第一篇【持续更新】
- Java进阶之欧拉工程 第十四篇【 最长的collatz序列】
- Java进阶之欧拉工程 第十八篇【 找出从三角形顶端走到底端的最大和】
- Java进阶之欧拉工程 第十七篇【用英文写出1到1000的所有数字需要多少个字母?】
- Java进阶之欧拉工程 第十六篇【2的1000次方各位之和为多少】
- Java进阶之欧拉工程 第十二篇【有大量约数的三角数】
- Java进阶之欧拉工程 第十三篇【大数求和】
- Java进阶之欧拉工程 第十五篇【网格路径问题】
- 关于java项目工程一下乱七八糟问题记录(持续更新)
- java学习中的英语(持续更新)
- 小米手机(MIUI)介绍以及工程机评测 【持续更新】