UVa 10177 (2/3/4)-D sqr/rects/cubes/boxes? (A good maths problem)

Source: Internet
Author: User
Tags count time limit

10177-(2/3/4)-D sqr/rects/cubes/boxes?

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem &problem=1118

You can have a (4x4) grid below. Can tell me how many squares and rectangles are hidden there? You can assume this squares are not rectangles. Perhaps one can count it by hand but can your count it for a (100x100) grid or a (10000x10000) grid. Can you does it for higher dimensions? This is can, count how many cubes or boxes the different size are there in a (10x10x10) sized the cube or how many Hyper-cub Es or hyper-boxes of different size are there in a four-dimensional (5x5x5x5) sized hypercube. Remember that your the needs to be very efficient. You can assume this squares are not rectangles, cubes are not boxes and hyper-cubes not are.

FIG:A 4x4 Grid Fig:a 4x4x4 Cube


The input contains one integer N (0<=n<=100) in each line, which is the length of one side of the grid or C Ube or hypercube. As for the example above the value of N is 4. There May is as many as lines of input.


For each line of input, output six integers S2, R2, S3, R3, S4, R4 in a single line where S2 means no of Squares of different size in (NxN) two-dimensional grid, R2 means no of rectangles of different size I n (NxN) two-dimensional grid. S3, R3, S4, R4 means similar cases in higher dimensions as described before.

Sample Input:


Sample Output:

1 0 1 0 1 0
5 4 9 18 17 64
14 22 36 180 98 1198


Take two-dimensional as an example, how does the number of squares count?

1x1 must have NXN, the 2x2 is (n-1) * (n-1) ... NXN only 1, is the square and formula.

The same three-dimensional is cubic and formula, four-dimensional is 4 power sum.

Then we ask for the number of rectangles containing squares, minus the number of squares to find out the number of square rectangles, how to ask?

We can think of it this way: Each side takes two lines, and the two lines can make a rectangle (of course, it can be a square, and a square is a rectangle).

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.