Mainly understanding the problem: the length of the cube is divided into N to N * N * N small cube, seeking a common vertex count how many small cube less than 2.
Public number of vertices of the cube has a pair of small 0,1,2,4 these four cases, we only need to calculate a common vertex with four small cube of the number. When only two small cube having a common plane, i.e. at the same X-axis or Y-axis in the same or the same Z-axis, a common number of vertices is four.
In the same X-axis, for example, small cubes line N, selecting a common two faces, a total of N-1 compounds selected method. Large cube side length is N, so that a total of N * N X-axis, i.e., a total of (N-1) * N * N group have a common plane of the small cubes. Likewise the Y-axis and Z-axis, i.e., a large cube consensus (N-1) * N * N * 3 groups of small cubes common plane.
Large cube array having a small cube of C (N * N * N, 2) = (N * N * N) * (N * N * N - 1) / 2, so that the common vertex number of small cubes of not more than 2 the group number (N * N * N) * (N * N * N - 1) / 2 - (N-1) * N * N * 3.
#include <iostream>
using namespace std;
int main()
{
int N;
while (cin >> N)
{
cout << (N * N * N) * (N * N * N - 1) / 2 - (N - 1) * N * N * 3 << endl;
}
return 0;
}
Keep up.