题目6:平方和与和平方的差是多少?
来源:互联网 发布:阿里云香港主机 翻墙 编辑:程序博客网 时间:2024/05/02 04:16
前十个自然数的平方和是:
12 + 22 + ... + 102 = 385
前十个自然数的和的平方是:
(1 + 2 + ... + 10)2 = 552 = 3025
所以平方和与和的平方的差是3025 385 = 2640.
找出前一百个自然数的平方和与和平方的差。
暴力算
public class Problem6 { public static void main(String[] args) { System.out.println(getSumSquare() - getSquareSum()); } private static long getSquareSum() { long squareSumRes = 0; for (int i = 1; i < 101; i++) { squareSumRes += Math.pow(i, 2); } return squareSumRes; } private static long getSumSquare() { int sum = 0; for (int i = 1; i < 101; i++) { sum += i; } return Math.round(Math.pow(sum, 2)); }}
0 0
- 题目6:平方和与和平方的差是多少?
- 平方和与和平方的差是多少?
- 欧拉工程第6题 平方和与和平方的差是多少
- 欧拉工程第六题 平方和与和平方的差是多少
- 平方和与和平方
- HDU 1421 差的平方和最小
- 006:欧拉项目平方和与和的平方的差
- 两个人生日的差是多少
- 分桶法和平方分割
- 分桶发和平方分割
- 分桶法和平方分割
- java回归中的残差平方和的均值
- 分桶法和平方分割(对区间的操作)
- java实现两个数的加减乘除和平方运算
- [研发与团队]和平典范的例子
- 快速平方根和平方计算
- 和的平方与平方和的差值
- 第三方公司的风格是多少的观点
- HDU 1712 ACboy needs your help-dp-(分组背包模型)
- 黑马程序员--C语言scanf()和gets()区别。
- ubuntu14.10 安装git并且使用CSDN提供的git服务器管理项目代码
- 组合模式——探索之旅
- LeetCode之Implement strStr()
- 题目6:平方和与和平方的差是多少?
- android:R.string.xx 转为字符型
- 用“牛顿迭代法”求根号2的近似值
- linux程序调试命令addr2line之入门简介(本文先不聊gdb调试)
- C语言-求数字阶乘(递归函数)
- 一些Python代码
- [2014-08-17 17:04:49 - ddms] transfer error: Invalid argument [2014-08-17 17:04:49] Failed to push s
- UML类图与类的关系详解
- 关于Objective-C 对象release操作的一个小问题探讨