# Find the difference between the square of the sum and the sum of the squares for the first hundred numbers

The sixth Project Euler problem - Sum Square Difference - is stated as follows.

The sum of the squares of the first ten natural numbers is 385. The square of the sum of the first ten natural numbers is 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.

Project Euler, Sum Square Difference, Problem 6

``````// Square the sum of the N first digits.
// That is, square the triangle number.
fn square_sum(n: u32) -> u32 {
(n*(n+1)/2).pow(2)
}

// Sum the squares of the N first digits.
fn sum_squares(n: u32) -> u32 {
((n*(n+1)*(2*n+1))/6)
}

// Find the difference between the square of the sum
// and the sum of the squares.
fn find_squares_difference(n: u32) -> u32 {
square_sum(n) - sum_squares(n)
}

fn main() {
let n = 100;
println!(
"The difference is {} with n = {}.",
find_squares_difference(n),
n,
);
}``````