Cube (hd1220)

Source: Internet
Author: User

Cube

Point Me

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 Input123

Sample Output016297 This is purely a mathematical question, and the reasoning is as follows: give you a cube, cut into small cubes of unit volume, and ask for the logarithm of the small cube of all public vertex numbers <=2. The number of public points can only be: 0,1,2,4. It is clear that we can subtract the logarithm of four common points with a total logarithm. Total Common point logarithm: n^3* (n^3-1)/2 (there are altogether n^3 block, select 2 pieces from the box (only two small squares between the existence of common points, we from all the small squares arbitrarily selected two, naturally determine the two small squares of the common points of the logarithm, from all the small squares arbitrarily select two, the total number of methods is the sum of all kinds of logarithms! )   the logarithm of the common point is 4: A column has n-1 pairs (n small squares, adjacent two for a pair of matching requirements), a face of the common n^2 column, the bottom and the left, the front three directions the same, the same can be, the total number is: 3*n^2 (n-1)
So the result is: N^3 * (n^3-1)-3*n^2 (n-1)
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5 using namespacestd;6 intMain ()7 {8     intnum;9      while(cin>>num)Ten     { One         intsum= (NUM,3) * (POW (num,3)-1)/2)-pow (NUM,2)*3* (num-1); Acout<<sum<<Endl; -     } -}

Cube (hd1220)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.