The reasoning is as follows:
Known: 1 ^ 2 + 2 ^ 2 + 3 ^ 2 + ...... + N ^ 2 = n (n + 1) (2n + 1)/6-①
So 1 ^ 2 + 2 ^ 2 + 3 ^ 2 + ...... + N ^ 2 + ...... + (2n + 1) ^ 2 = (2n + 1) (n + 1) (4n + 3)/3-②
There are 2 ^ 2 + 4 ^ 2 + 6 ^ 2 + ...... + (2n) ^ 2 = 4 [1 ^ 2 + 2 ^ 2 + 3 ^ 2 + ...... + N ^ 2] = 4 * ① = 2n (n + 1) (2n + 1)/3-③
Set the value to S for comparison. ② and ③ we can see that S = ②-③ = (2n + 1) (n + 1) (4n + 3)/3-2n (n + 1) (2n + 1)/3
= (2n + 1) (n + 1) (2n + 3)/3-④
Because S is the sum of 2n + 1, and it is generalized, then the sum of squares of odd items. General Formula: Sn = n (n + 1) (N + 2)/6
Be sure to use long to ensure no overflow!
# Include <iostream> # include <vector> # include <map> # include <stack> # include <algorithm> # include <queue> # include <list> # include <set> # include <string. h> # include <stdlib. h> # include <math. h> # include <stdio. h> # include <ctype. h >#include <iomanip> using namespace STD; # define ll long longint main () {ll N; while (scanf ("% i64d", & N )! = EOF) {ll ans = N * (n + 1) * (N + 2)/6; printf ("% i64d \ n", ANS);} return 0 ;}