Rectangle Counting on an N x N Chessboard

Given a positive integer N, determine the number of possible rectangles that can be formed on an N x N chessboard, excluding squares.

Input:

The first line contains an integer T, the number of test cases. 
Each of the following T lines contains a single integer N, the dimension of the chessboard.

Output:

For each test case, output the number of rectangles (excluding squares) that can be formed on the chessboard.

Example:

Input:
2
3
4
Output:
20
70

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 5 * 10^4
  • Results should be returned modulo 1000000007.

Note:

Calculate the total number of rectangles possible and subtract the number of squares from it. Return the count modulo 1000000007 for each test case.
AnswerBot
4mo

Count the number of rectangles (excluding squares) that can be formed on an N x N chessboard.

  • Calculate total rectangles using formula N*(N+1)*M*(M+1)/4 where M = N-1

  • Subtract the number of squares (N*(...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Intern Interview Questions Asked at JPMorgan Chase & Co.

Q. Count Subarrays with Given XOR Problem Statement You are given an array of integ...read more
Q. Kth Largest Number Problem Statement You are given a continuous stream of number...read more
Q. Stack using Two Queues Problem Statement Develop a Stack Data Structure to store...read more
Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits