码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1220 Cube 简单数论

时间:2015-03-12 15:08:38      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:hdu1220   数论   cube   

Cube

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


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.
/*
给你一个边长n的正方体,切割成n*n*n个单位体积的小正方体,求所有公共顶点数<=2的小正方体的对数。  
公共点的数目可能有:0,1,2,4.  
我们用总的对数减掉有四个公共点的对数就可以了。  
总的对数:n^3*(n^3-1)/2(一共有n^3块小方块,从中选出2块)  
公共点为4的对数:一列有n-1对(n个小方块,相邻的两个为一对符合要求),一个面的共有 n^2列,  
底面和左面,前面三个方向相同,同理可得,故总数为:3*n^2(n-1)  
所以结果为: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 ;
}

与君共勉

hdu 1220 Cube 简单数论

标签:hdu1220   数论   cube   

原文地址:http://blog.csdn.net/lionel_d/article/details/44221287

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!