Given a number n, we need to find the maximum number of times n circles intersect.

Examples:

Input : n = 2 Output : 2 Input : n = 3 Output : 6

## Description and Derivation

As we can see in above diagram, for each pair of circles, there can be maximum two intersectuib points. Therefore if we have n circles then there can be ^{n}C_{2} pairs of circles in which each pair will have two intersections. So by this we can conclude that by looking at all possible pairs of circles the mathematical formula can be made for the maximum number of intersection by n circles is given by **2 * ^{n}C_{2}**.

2 * ^{n}C_{2} = 2 * n * (n – 1)/2 = **n * (n-1)**

## C++

`// CPP program to find maximum umber of ` `// intersections of n circles ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Returns maximum number of intersections ` `int` `intersection(` `int` `n) ` `{ ` ` ` `return` `n * (n - 1); ` `} ` ` ` `int` `main() ` `{ ` ` ` `cout << intersection(3) << endl; ` ` ` `return` `0; ` `} ` `// This code is contributed by ` `// Manish Kumar Rai. ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find maximum umber of ` `// intersections of n circles ` `import` `java.io.*; ` ` ` `public` `class` `GFG { ` ` ` ` ` `// for the calculation of 2*(nC2) ` ` ` `static` `int` `intersection(` `int` `n) ` ` ` `{ ` ` ` `return` `n * (n - ` `1` `); ` ` ` `} ` ` ` ` ` `public` `static` `void` `main(String[] args) ` `throws` `IOException ` ` ` `{ ` ` ` `System.out.println(intersection(` `3` `)); ` ` ` `} ` `} ` `// This code is contributed by ` `// Manish Kumar Rai ` |

*chevron_right*

*filter_none*

## Python3

`# python program to find maximum umber of ` `# intersections of n circles ` `# Returns maximum number of intersections ` `def` `intersection(n): ` ` ` ` ` `return` `n ` `*` `(n ` `-` `1` `); ` ` ` `# Driver code ` `print` `(intersection(` `3` `)) ` ` ` `# This code is contributed by Sam007 ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find maximum umber of ` `// intersections of n circles ` `using` `System; ` `class` `GFG { ` ` ` ` ` `// for the calculation of 2*(nC2) ` ` ` `static` `int` `intersection(` `int` `n) ` ` ` `{ ` ` ` `return` `n * (n - 1); ` ` ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main() ` `{ ` ` ` `Console.WriteLine(intersection(3)); ` `} ` ` ` `} ` ` ` `// This code is contributed by Sam007 ` |

*chevron_right*

*filter_none*

## php

`<?php ` `// php program to find maximum umber of ` `// intersections of n circles ` ` ` `// Returns maximum number of intersections ` `function` `intersection(` `$n` `) ` `{ ` ` ` `return` `$n` `* (` `$n` `- 1); ` `} ` ` ` `// Driver code ` ` ` `echo` `intersection(3); ` ` ` ` ` `// This code is contributed by Sam007 ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

6

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- 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
- Maximum points of intersections possible among X circles and Y straight lines
- Maximum points of intersection n lines
- Number of pairs of lines having integer intersection points
- Number of Integral Points between Two Points
- Prime points (Points that split a number into two primes)
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Minimum number of points to be removed to get remaining points on one side of axis
- Ways to choose three points with distance between the most distant points <= L
- Steps required to visit M points in order on a circular ring of N points
- Find the point on X-axis from given N points having least Sum of Distances from all other points
- Maximum possible intersection by moving centers of line segments
- Maximum number of line intersections formed through intersection of N planes
- Length of the transverse common tangent between the two non intersecting circles
- Check if two given circles touch or intersect each other
- Check whether given circle resides in boundary maintained by two other circles
- Check if a given circle lies completely inside the ring formed by two concentric circles
- Calculate Stirling numbers which represents the number of ways to arrange r objects around n different circles
- Radii of the three tangent circles of equal radius which are inscribed within a circle of given radius

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.