Maximum points of intersection n circles - GeeksforGeeks

17 Dec, 2021
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
As we can see in above diagram, for each pair of circles, there can be maximum two intersection points. Therefore if we have n circles then there can be nC2 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 intersections by n circles is given by 2 * nC2. 2 * nC2 = 2 * n * (n – 1)/2 = n * (n-1)
C++
Java
Python3
C#
PHP
Javascript
// CPP program to find maximum number of// intersections of n circles#include <bits/stdc++.h>using namespace std; // Returns maximum number of intersectionsint intersection(int n){   return n * (n - 1);} int main(){    cout << intersection(3) << endl;    return 0;}// This code is contributed by// Manish Kumar Rai.
// Java program to find maximum number of// intersections of n circlesimport 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
# python program to find maximum number of# intersections of n circles# Returns maximum number of intersectionsdef intersection(n):        return n * (n - 1); # Driver codeprint(intersection(3)) # This code is contributed by Sam007
// C# program to find maximum number of// intersections of n circlesusing System;class GFG {     // for the calculation of 2*(nC2)    static int intersection(int n)    {        return n * (n - 1);    } // Driver Codepublic static void Main(){    Console.WriteLine(intersection(3));} } // This code is contributed by Sam007
<?php// php program to find maximum number of// intersections of n circles // Returns maximum number of intersectionsfunction intersection($n){   return $n * ($n - 1);}  // Driver code echo intersection(3);  // This code is contributed by Sam007?>
<script>// Javascript program to find maximum number of// intersections of n circles // Returns maximum number of intersectionsfunction intersection(n){   return n * (n - 1);}  // Driver codedocument.write(intersection(3)); // This code is contributed by _saurabh_jaiswal </script>
6
 
Sam007
nidhi_biet
_saurabh_jaiswal
sagar0719kumar
sumitgumber28
circle
Combinatorial
Geometric
Mathematical
Mathematical
Combinatorial
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Ways to sum to N using Natural Numbers up to K with repetitions allowed
Generate all possible combinations of K numbers that sums to N
Combinations with repetitions
Largest substring with same Characters
Generate all possible combinations of at most X characters from a given array
Closest Pair of Points using Divide and Conquer algorithm
How to check if a given point lies inside or outside a polygon?
Program for distance between two points on earth
How to check if two given line segments intersect?
Find if two rectangles overlap