操作
Problem 6¶
Sum Square Difference¶
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
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個の自然数について二乗の和と和の二乗の差を求めよ.
#!r6rs
#!chezscheme
(import (chezscheme))
(define square-nums
(map
(lambda (n) (expt n 2))
(iota 101)))
(define square-sum
(apply + square-nums))
(define sum-square
(expt (apply + (iota 101))
2))
(define answer-6
(- sum-square square-sum))
(printf "6: ~D~%" answer-6)
Noppi が2023/12/29に更新 · 4件の履歴