Number of triangles

3.4

95 votes
Basic Programming, Inclusion-exclusion, Math
Problem

You are given a polygon of N sides with vertices numbered from 1, 2, ..., N. Now, exactly 2 vertices of the polygons are colored black and remaining are colored white. You are required to find the number of triangles denoted by A such that:

  1. The triangle is formed by joining only the white-colored vertices of the polygon.
  2. The triangle shares at least one side with the polygon.

Input format

  • The first line contains t denoting the number of test cases.
  • Next t lines contain three space-separated integers NB1, and B2 where N is the number of sides in the polygon and B1,B2 denote the vertices that are colored black.

Output format

For each test case, print the answer A representing the number of triangles that can be formed with the given conditions in the problem statement. 

Constraints

1t100

5N105

1B1,B2N

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The number of triangles which satisfy the property are 4  - 136 , 146 , 346 and 134 

Editor Image

?