Cowl is good at solving math problems. One day a friend asked him such a question: You are given a cube whose edge length is N, it is cut by the planes that was paralleled to its side planes into N * N * N unit cubes. Two unit cubes may have no common points or two common points or four common points. Your job is to calculate how many pairs of unit cubes that have no more than two common points.
Process to the end of file.
Process to the end of file.
1 2 3
0 16 297 The results will not exceed int type.
Hint#include<stdio.h> #include<string.h> #include<math.h> using namespace std; int dp[35]; int F(int n){ int sum=1; sum*=n*(n-1); sum/=2; return sum; } void init(){ dp[1]=0; for(int i=2;i<=30;i++){ int n=(int)pow(i,3); dp[i]=F(n)-(int)pow(i,2)*3*(i-1); } } int main(){ int m; init(); while(scanf("%d",&m)!=EOF){ printf("%d\n",dp[m]); } return 0; }