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.
前十个正自然数的平方的和如下,
前十个正自然数的和的平方如下,
因此前10个正自然数的和的平方与前10个正自然数的平方的和的差是 3025 385 = 2640.
求前100个正自然数的和的平方与前100个正自然数的平方的和的差是多少.
public class Euler6 { public static void main(String[] args) { int sumSquare=0,t=0,squareSum=0; for(int i=1;i<=100;i++) { squareSum+=i*i; } t=100*(100+1)/2; sumSquare=t*t; System.out.print("平方和之差="); System.out.println(sumSquare-squareSum); } }
本文出自 “迁客的小屋” 博客,请务必保留此出处http://qianke.blog.51cto.com/5616176/1391173
原文:http://qianke.blog.51cto.com/5616176/1391173