hdu 1220 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 ;
}

与君共勉

时间: 2024-08-29 16:57:32

hdu 1220 Cube 简单数论的相关文章

题解报告:hdu 1220 Cube

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1220 问题描述 Cowl擅长解决数学问题. 有一天,一位朋友问他这样一个问题:给你一个边长为N的立方体,它被与其侧面平行的平面切割成N * N * N个单位立方体. 两个单位立方体可能没有共同点或两个共同点或四个共同点. 你的工作是计算有多少对不超过两个公共点的单位立方体.处理到文件的结尾. 输入 会有很多测试用例. 每个测试用例只会在一行中给出一个立方体的边长N. N是正整数(1 <= N <=

HDU(1220)——Cube

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 cub

hdu 1214 圆桌会议 简单数论

圆桌会议 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3328    Accepted Submission(s): 2328 Problem Description HDU ACM集训队的队员在暑假集训时经常要讨论自己在做题中遇到的问题.每当面临自己解决不了的问题时,他们就会围坐在一张圆形的桌子旁进行交流,经过大家的讨论后一般没有

hdu 1220 Cube (组合数学)

/* 给你一个边长n的正方体,切割成n*n*n个单位体积的小正方体,求所有公共顶点数<=2的小正方体的对数. 公共点的数目可能有:0,1,2,4. 我们用总的对数减掉有四个公共点的对数就可以了. 总的对数:n^3*(n^3-1)/2(一共有n^3块小方块,从中选出2块) 而4个交点的立方体对是两个立方体共面的情况, 所以我们只要求出大的立方体一共有多少个单位面积的公共面就可以了, 既所有单位立方体的面数6*n^3减去在大立方体表面的面数6*n^2就可以了,, 所以结果为:n^3 * (n^3-1

hdu 1395 2^x mod n = 1 (简单数论)

题目大意: 求出一个最小的x 使得 2的x次方对n取模为1 思路分析: 若要 a*b%p=1  要使得b存在 则 gcd (a,p)=1. 那么我们应用到这个题目上来. 当n为偶数 2^x 也是偶数,那么gcd 肯定不是1.故这个是不存在的. 那么n为奇数的时候,也就一定是1了. 所以直接暴力找. #include <iostream> #include <cstdio> using namespace std; int main() { int n; while(scanf(&q

HDU 4861 Couple doubi(数论)

HDU 4861 Couple doubi 题目链接 题意:给定k,p,有k个球,每个球的值为1^i+2^i+...+(p-1)^i (mod p) (1 <= i <= k),现在两人轮流取球,最后球的值总和大的人赢,问先手是否能赢 思路:先手不可能输,非赢即平,那么只要考虑每种球的值, 利用费马小定理或欧拉定理,很容易得到该函数的循环节为p - 1, 那么i如果为p - 1的倍数,即为循环节的位置,那么每个值都为1,总和为p - 1 如果i不在循环节的位置,任取一个原根g,根据原根的性质,

HDU 3049 Data Processing 数论题解

Problem Description Chinachen is a football fanatic, and his favorite football club is Juventus fc. In order to buy a ticket of Juv, he finds a part-time job in Professor Qu's lab. And now, Chinachen have received an arduous task--Data Processing. Th

HDU 1221: Cube

HDU 1221: Cube ///@author Sycamore, ZJNU ///@accepted_on 2017-01-24 #include<iostream> using namespace std; int main() { int N; while (cin >> N) cout << N*N*N *(N*N*N - 1) / 2 - 3 * (N - 1)*N*N << endl; return 0; }

HDU - 3584 Cube (三维树状数组 + 区间改动 + 单点求值)

HDU - 3584 Cube Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the number in the i-th row , j-th column and k-th layer. I