欧拉计划 第6题
来源:互联网 发布:网络直播视频 编辑:程序博客网 时间:2024/04/27 05:18
题目
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.
找出前一百个自然数的平方和与和平方的差。
前十个自然数的平方和是:
前十个自然数的和的平方是:
(1 + 2 + ... + 10)2 = 552 = 3025
所以平方和与和的平方的差是3025 - 385 = 2640.
解答:该题数据规模不大,直接计算就可以了。Java程序
public class N_6 {public static void main(String []args){int n=100;int number1=0,number2=0;for(int i=1;i<=n;i++){number1=number1+i*i;number2=number2+i;}number2=number2*number2;System.out.println(number2-number1);}}
运行结果:25164150
0 0
- 欧拉计划 第6题
- 欧拉计划第2题
- 欧拉计划 第1题
- 欧拉计划 第2题
- 欧拉计划 第3题
- 欧拉计划 第4题
- 欧拉计划 第5题
- 欧拉计划 第7题
- 欧拉计划 第8题
- 欧拉计划 第9题
- 欧拉计划 第10题
- 欧拉计划第3题
- 欧拉计划第4题
- 欧拉计划第5题
- 欧拉计划 6
- 欧拉计划:第12,13,14题
- 欧拉计划第52题的Python的实现
- python解答欧拉计划第59题
- Exercise 10: 那是什么?
- PHPCMS安装流程图
- IE下Css圆角问题
- UILocalizedIndexedCollation 使用
- HTML中忽略的小问题
- 欧拉计划 第6题
- cocos2d-x 自定义精灵类
- PAT 1073
- 遠端存取SQL 2008 R2 Express方法
- 【linux学习笔记】sort|uniq | cut | wc (我的第一篇markdown笔记)
- 逐梦之路充满艰辛
- Nginx初识
- 常用正则表达式
- Dialect class not found: org.hibernate.dialect.Oracle10gDialect 报错解决