hdoj 1220Cube

来源:互联网 发布:数据交换共享平台源码 编辑:程序博客网 时间:2024/06/03 22:08

Cube


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1771    Accepted Submission(s): 1405

Problem Description
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.

 

Input

There will be many test cases. Each test case will only give the edge length N of a cube in one line. N is a positive integer(1<=N<=30).
 
Output
For each test case, you should output the number of pairs that was described above in one line.
 
Sample Input
1
2
3
 
Sample Output
0
16

297


Hint
Hint
 
The results will not exceed int type.
 
Author
Gao Bo
 
Source

杭州电子科技大学第三届程序设计大赛


翻译:

有一天,一个朋友问他这样一个问题:你是给一个立方体的边长度是氮,它被削减的飞机,是平行的,其侧面的飞机到氮的单位立方体。2个单位的多维数据集可能没有共同点或2个共同点或四个共同点。你的任务是计算出有多少双单位立方体没有超过2个共同点。
进程到文件结束。
输入
将有许多测试案例。每一个测试用例只会给一个数据线中的一个立方体的边长度。正整数(1 = 30)。
输出
对于每一个测试用例,你应该输出一行上面描述的对的数目。



代码:

#include<cstdio>#include<cstring>#define LL long longint main(){int n;while (~scanf("%d",&n)){LL s=0,shu,mian;mian=(n-2)*(n-2);shu=n*n*n;s=shu*(shu-7);s+=mian*6;s+=(n-2)*24;s+=8*3;printf("%lld\n",s/2);}return 0; } 


0 0