Uvalive 6602 counting lattice squares [ry] [wit]

Source: Internet
Author: User

Question link: https://icpcarchive.ecs.baylor.edu/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 4613

Give you a matrix lattice of N * m. In the matrix lattice of N * m, you need to select four points to form a square, so that the square area is odd, ask how many such squares can be formed.

Question: Start from every odd number as a basic unit.

Area edge Square:

1*1 1 1

3*3 3 SQRT (5)1 + 1*2

5*5 5 SQRT (17) SQRT (13)1 + 2*2

7*7 7 SQRT (37) SQRT (29) SQRT (25) 1 + 3*2

......

A square with M * n can form a square with x (m-x + 1) * (N-x + 1 ).

 
# Include <iostream> # include <stdio. h >#include <cstring> using namespace STD; # define maxn 100005 # define ll long longll A [maxn]; int main () {ll M, N; while (~ Scanf ("% LLD", & M, & N) {If (M = 0 & n = 0) break; ll ans = 0; for (ll I = 1; I <= min (m, n); I + = 2) {ans + = (M-I + 1) * (N-I + 1) * (I/2*2 + 1);} printf ("% LLD \ n", ANS );}}



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.