How to return long from a method when the return value is greater than long?
<p>I am trying to solve a problem in Topcoder, where I need to find the number of rectangles(excluding squares) when the width and length are provided. My code works perfect for all test cases, but for one final test case, ie <code>592X964</code> I need to return <code>81508708664</code> , which is greater than <code>2^32-1</code> , which is greater than the value long can hold, but the compiler demands the value must be returned in <code>long</code> . I've added the problem statement and my code below, kindly go through, and let me know if its possible to return the above value using long in java. </p>

<pre><code>    /*
Problem Statement
    
Given the width and height of a rectangular grid, return the total number of rectangles (NOT counting squares) that can be found on this grid.
For example, width = 3, height = 3 (see diagram below):
 __ __ __
|__|__|__|
|__|__|__|
|__|__|__|
In this grid, there are 4 2x3 rectangles, 6 1x3 rectangles and 12 1x2 rectangles. Thus there is a total of 4 + 6 + 12 = 22 rectangles. Note we don't count 1x1, 2x2 and 3x3 rectangles because they are squares.
Definition
    
Class:
RectangularGrid
Method:
countRectangles
Parameters:
int, int
Returns:
long
Method signature:
long countRectangles(int width, int height)
(be sure your method is public)
Limits
    
Time limit (s):
2.000
Memory limit (MB):
64
Notes
-
rectangles with equals sides (squares) should not be counted.
Constraints
-
width and height will be between 1 and 1000 inclusive.
Examples
0)

    
3
3
Returns: 22
See above
1)

    
5
2
Returns: 31
 __ __ __ __ __
|__|__|__|__|__|
|__|__|__|__|__|
In this grid, there is one 2x5 rectangle, 2 2x4 rectangles, 2 1x5 rectangles, 3 2x3 rectangles, 4 1x4 rectangles, 6 1x3 rectangles and 13 1x2 rectangles. Thus there is a total of 1 + 2 + 2 + 3 + 4 + 6 + 13 = 31 rectangles.
2)

    
10
10
Returns: 2640

3)

    
1
1
Returns: 0

4)

    
592
964
Returns: 81508708664

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
*/
public class RectangularGrid
{
    public static void main(String[] args)
    {
        System.out.println(countRectangles(592,964));
    }

    public static long countRectangles(int m, int n)
    {
        long tot_rect = (long)(((m*m)+m)*((n*n)+n))/4;
        long tot_square = 0;
        boolean status = true;

        while(status)
        {
            if(m&gt;0 &amp;&amp; n&gt;0)
            {
                tot_square+=(long)m*n;
                --m;
                --n;
            }
            else
            {
                status = false;
            }

        }


        return tot_rect-tot_square;
    }
}
</code></pre>