-D sqr/rects/cubes/boxes?

Source: Internet
Author: User

I have put a question for a long time. Today, a is actually a formula. The only thing I think is that the placeholder for long in Windows is % i64d, however, it seems that the system uses Linux. For this reason, wR checked
Change to % LLD and then AC.
Solution:
For square blocks, it is better to look for the law. For example, the square with a side length of 4 is: 1 + 4 + 9 + 25 = 39. that is, the sum of the squares of the preceding edges. The three-dimensional four-dimensional values correspond to the cubic and the fourth power.
For rectangular cubes with different edges and lengths, the formula is required:
It can be found that in a graph, the side length with a side length of 1 has n optional positions on each of the largest sides. For example, the side length is 2 (that is, when n = 2 is input ), each maximum edge has n (n = 2) and N-1 (n-1 = 1) the optional position of a small side with a side length of 2, and so on... so the number of all possible edges in the rectangle is {n + (n-1) +... + 2 + 1} = N * (1 + N)/2, select either of the two possibilities
You can create a rectangle. And then subtract the number of rectangles. The number of edges may be equal ~

CodeAs follows:

# Include <iostream> # include <cstdlib> # include <cstring> # include <cstdio> # include <cmath> using namespace STD; int main () {# ifdef test freopen ("in.txt", "r", stdin); # endif int num; long int S2, R2, S3, R3, S4, R4; while (scanf ("% d", & num )! = EOF) {S2 = R2 = S3 = R3 = S4 = r4 = 0; For (INT I = 1; I <= num; I ++) {S2 + = I * I; S3 + = I * I; S4 + = I * I ;} long long int M = num * (Num + 1)/2; r2 = m * m-S2; R3 = m * m-S3; r4 = m * m-S4; printf ("% LLD \ n", S2, R2, S3, R3, s4, R4);} return 0 ;}

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.