Number of triangles
Practice
3.4 (95 votes)
Basic programming
Inclusion Exclusion
Math
Problem
65% Success 23062 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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:
- The triangle is formed by joining only the white-colored vertices of the polygon.
- 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 \(N\), \(B1\), 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
\(1 \le t \le 100\)
\(5\le N \le10^5\)
\(1\le B1, B2 \le N\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
319 votes
Tags:
Ad-HocEasyOpen
Points:20
48 votes
Tags:
ApprovedBasic ProgrammingEasyImplementationOpen
Points:20
264 votes
Tags:
ApprovedBasic ProgrammingEasyOpen
Editorial