CubeTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1516 Accepted Submission (s): 1206
Problem Descriptioncowl is good at solving math problems. One day a friend asked him such a question:you be given a cube whose edge length is N, it's cut by the planes Paralleled to it side planes into n * n * n unit cubes. Both unit cubes may have no common points or both common points or four common points. Your job is to calculate how many pairs of unit cubes that has no more than and common points.
Process to the end of file.
Inputthere'll be many test cases. Each test case would only be give the edge length N of a cube in one line. N is a positive integer (1<=n<=30).
Outputfor Each test case, you should output the number of pairs is described above in one line.
Sample Input
123
Sample Output
016297HintHintThe results would not exceed int type.
/* give you a square with a side length of N, cut into a small cube of n*n*n units, and ask for the logarithm of the small cube of all public vertex numbers <=2. the number of public points may be: 0,1,2,4. We can subtract the logarithm of four common points with the total logarithm. Total logarithm: n^3* (n^3-1)/2 (altogether there are n^3 blocks, from which 2 blocks are selected) The common point is 4 logarithm: A column has n-1 pairs (n small squares, adjacent two for a pair of matching requirements), a face of the total n^2 column, the bottom and the left, The first three directions are the same, so the total is: 3*n^2 (n-1) So the result is: N^3 * (n^3-1)/2-3*n^2 (n-1) */ #include <stdio.h>int main () {int n; while (~SCANF ("%d", &n)) {printf ("%d\n", n*n*n* (n*n*n-1)/2-3* (n-1) *n*n);} return 0;}
with June
HDU 1220 Cube Simple number theory