The sum of the squares of the first ten natural numbers is,
1^2 + 2^2 + ... + 10^2 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^2 = 55^2 = 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個の自然数の2乗の和は
1^2 + 2^2 + ... + 10^2 = 385
最初の10個の自然数の和の2乗は
(1 + 2 + ... + 10)^2 = 55^2 = 3025
最初の10個の整数の2乗の和と和の2乗の差は 3025 - 385 = 2640 です。
最初の100個の整数の2乗の和と和の2乗の差を求めなさい。
A = Sum[i, {i, 1, 100}]^2
B = Sum[i^2, {i, 1, 100}]
A - B
う〜ん、楽しすぎてるなぁ。
#include <iostream>
using namespace std;
int main(){
int sum1=0, sum2=0;
for(int i=1 ; i<=100 ; i++){
sum1 += i*i;
sum2 += i;
}
sum2 *= sum2;
cout << sum2-sum1 << endl;
}
と思ったらC++も即終了だった