Hdu2524 (calculate the number of rectangles, questions ...), Hdu2524 rectangle

Source: Internet
Author: User

Hdu2524 (calculate the number of rectangles, questions ...), Hdu2524 rectangle

 

Hdu 2524N-brute force solution and table Creation Time Limit:1000 MS Memory Limit:32768KB 64bit IO Format:% I64d & % I64u

Description

A grid with a height of n and a width of m columns is provided. The number of rectangles in the grid is calculated. The grid with a height of 2 and a width of 4 is displayed.
 

Input

Input a t in the first line, indicating that there is a t group of data, and then input n, m in each line, indicating the height and width of the grid respectively (n <100, m <100 ).

Output

The number of rectangles in the output grid of each row.

Sample Input

21 22 4

Sample Output

330

It seems that the solution to this question is violent, but it is good to find its mathematical law.

Number of rectangles = n * (n + 1)/2 * m * (m + 1)/2

 

AC code:

#include<iostream>using namespace std;int main(){    int t,n,m,s;    cin>>t;    while(t--)    {        cin>>n>>m;        s=n*(n+1)/2*m*(m+1)/2;        cout<<s<<endl;    }       return 0;}

 

Related Article

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.