Given two integers **X** and **Y**, the task is to find the maximum number of points of intersection possible among **X** circles and **Y** straight lines.

**Example:**

Input:X = 4, Y = 4

Output:50

Explanation:

4 lines intersect each other at 6 points and 4 circles intersect each other at maximum of 12 points.

Each line intersects 4 circles at 8 points.

Hence, 4 lines intersect four circles at a maximum of 32 points.

Thus, required number of intersections = 6 + 12 + 32 = 50.

Input:X = 3, Y = 4

Output:36

**Approach:**

It can be observed that there are three types of intersections:

- The number of ways to choose a pair of points from X circles is . Each such pair intersect at most two points.
- The number of ways to choose a pair of points from Y lines is . Each such pair intersect in at most one point.
- The number of ways to choose one circle and one line from X circles and Y lines is is . Each such pair intersect in at most two points.

So, the maximum number of point of intersection can be calculated as:

=>

=>

Thus, formula to find maximum number of point of intersection of **X** circles and **Y** straight lines is:

Below is the implementation of the above approach:

## C++

`// C++ Program of the above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `int` `maxPointOfIntersection(` `int` `x, ` `int` `y) ` `{ ` ` ` `int` `k = y * (y - 1) / 2; ` ` ` `k = k + x * (2 * y + x - 1); ` ` ` `return` `k; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` ` ` `// Number of circles ` ` ` `int` `x = 3; ` ` ` ` ` `// Number of straight lines ` ` ` `int` `y = 4; ` ` ` ` ` `// Function Call ` ` ` `cout << (maxPointOfIntersection(x, y)); ` `} ` ` ` `// This code is contributed by Ritik Bansal ` |

*chevron_right*

*filter_none*

## Java

`// Java program to implement ` `// the above approach ` `class` `GFG{ ` ` ` `static` `int` `maxPointOfIntersection(` `int` `x, ` `int` `y) ` `{ ` ` ` `int` `k = y * (y - ` `1` `) / ` `2` `; ` ` ` `k = k + x * (` `2` `* y + x - ` `1` `); ` ` ` `return` `k; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` ` ` `// Number of circles ` ` ` `int` `x = ` `3` `; ` ` ` ` ` `// Number of straight lines ` ` ` `int` `y = ` `4` `; ` ` ` ` ` `// Function Call ` ` ` `System.out.print(maxPointOfIntersection(x, y)); ` `} ` `} ` ` ` `// This code is contributed by Princi Singh ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to implement ` `# the above approach ` `def` `maxPointOfIntersection(x, y): ` ` ` `k ` `=` `y ` `*` `( y ` `-` `1` `) ` `/` `/` `2` ` ` `k ` `=` `k ` `+` `x ` `*` `( ` `2` `*` `y ` `+` `x ` `-` `1` `) ` ` ` `return` `k ` ` ` `# Number of circles ` `x ` `=` `3` `# Number of straight lines ` `y ` `=` `4` ` ` `# Function Call ` `print` `(maxPointOfIntersection(x, y)) ` |

*chevron_right*

*filter_none*

## C#

`// C# program to implement ` `// the above approach ` `using` `System; ` ` ` `class` `GFG{ ` ` ` `static` `int` `maxPointOfIntersection(` `int` `x, ` `int` `y) ` `{ ` ` ` `int` `k = y * (y - 1) / 2; ` ` ` `k = k + x * (2 * y + x - 1); ` ` ` `return` `k; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` ` ` `// Number of circles ` ` ` `int` `x = 3; ` ` ` ` ` `// Number of straight lines ` ` ` `int` `y = 4; ` ` ` ` ` `// Function Call ` ` ` `Console.Write(maxPointOfIntersection(x, y)); ` `} ` `} ` ` ` `// This code is contributed by Princi Singh ` |

*chevron_right*

*filter_none*

**Output:**

36

**Time Complexity:** *O(1)*

**Auxiliary Space:** *O(1)*

## Recommended Posts:

- Puzzle | Connect 9 circles each arranged at center of a Matrix using 3 straight lines
- Count of intersections of M line segments with N vertical lines in XY plane
- Count of different straight lines with total n points with m collinear
- Count of rectangles possible from N and M straight lines parallel to X and Y axis respectively
- Count squares possible from M and N straight lines parallel to X and Y axis respectively
- Ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles
- Ratio of the distance between the centers of the circles and the point of intersection of two transverse common tangents to the circles
- Represent a given set of points by the best possible straight line
- Maximum number of line intersections formed through intersection of N planes
- Check if three straight lines are concurrent or not
- Check whether two straight lines are orthogonal or not
- Check if given two straight lines are identical or not
- Count straight lines intersecting at a given point
- Maximum XOR value of maximum and second maximum element among all possible subarrays
- Maximum points of intersection n circles
- Number of intersections between two ranges
- Check whether a straight line can be formed using N co-ordinate points
- Maximum points of intersection n lines
- Python - Find the maximum number of triangles with given points on three lines
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.