# Sum of area of alternative concentric circle with radius 1,2,3,4……….N

Given that Concentric circle of radii **1,2,3,4……….N** cm are drawn. The interior of the smallest circle is colored white and angular regions are colored alternately green and white so that no two adjacent regions are of the same color. The task is to find the total area of the green region in sq cm.

**Examples:**

Input:N=100Output:15865.042900628456

Input:N=10Output:172.78759594743863

**Approach:** Area of the first green region would be-

[Ï€(R2Â²- R1Â²)]

Similarly, the area of all alternative green circles would be-

[Ï€(R4Â²- R3Â²)], [Ï€(R6Â²- R5Â²)]…..

The total area of the green region is the sum of the area of the green region is-

A = [ Ï€ { (R2Â² – R1Â²) + (R4Â² – R3Â²) + (R6Â² – R5Â²) …………. (R(N)Â² – R(N-1)Â²}]

A = [ Ï€ { ((R2 – R1)(R2 + R1)) + ((R4 – R3)(R4 + R3)) + ((R6 – R5)(R6 + R5)) …………. ((RN – R(N – 1)(RN + R(N – 1)) } ]

Since the difference between the radius of 2 concentric circles is only 1 cm so **R(N) – R(N – 1) = 1. **Hence,

A = [ Ï€ {R1 + R2 + R3 + R4 + R5 + R6 ………….R(N-1) + R(N) } ]

(R1 + R2 + R3 + R4 + R5 + R6 ………….R(N-1) + R(N) forms an arithmetic progression so we have to find the sum of arithmetic progression with starting radius as 1 and last radius as N with a common difference of 1.

Sum of A.P. is-

S_{N}= N * (2 * a +(N – 1) * d) / 2or

S_{N}= N * (a + l) / 2

Thus, the area of the green region is-

A = Sn * Ï€

Below is the implementation of the above approach:

## C++

`// C++ code for the above approach` `#include <bits/stdc++.h>` `using` `namespace` `std;` `// Function to calculate area` `// of concentric circles` `double` `area(` `int` `N, ` `int` `a, ` `int` `l)` `{` ` ` `// Formula to find sum of` ` ` `// Arithmetic Progression` ` ` `double` `S = N * (a + l) / 2;` ` ` `// return area` ` ` `return` `S * M_PI;` `}` `// Driver code` `int` `main()` `{` ` ` ` ` `// N is number of concentric circles` ` ` `int` `N = 100;` ` ` `// Radius of interior circle` ` ` `int` `a = 1;` ` ` `// l radius of exterior circle` ` ` `int` `l = N;` ` ` `// r is result` ` ` `double` `r = area(N, a, l);` ` ` `// Print result` ` ` `cout << fixed << setprecision(12) << r;` `}` `// This code is contributed by Samim Hossain Mondal.` |

## Java

`// Java code for the above approach` `class` `GFG` `{` ` ` `// Function to calculate area` `// of concentric circles` `static` `double` `area(` `int` `N, ` `int` `a, ` `int` `l)` `{` ` ` `// Formula to find sum of` ` ` `// Arithmetic Progression` ` ` `double` `S = N * (a + l) / ` `2` `;` ` ` `// return area` ` ` `return` `S * Math.PI;` `}` `// Driver code` `public` `static` `void` `main(String args[])` `{` ` ` ` ` `// N is number of concentric circles` ` ` `int` `N = ` `100` `;` ` ` `// Radius of interior circle` ` ` `int` `a = ` `1` `;` ` ` `// l radius of exterior circle` ` ` `int` `l = N;` ` ` `// r is result` ` ` `double` `r = area(N, a, l);` ` ` `// Print result` ` ` `System.out.println(r);` `}` `}` `// This code is contributed by gfgking` |

## Python3

`# import pi from math module` `from` `math ` `import` `pi` `# Function to calculate area` `# of concentric circles` `def` `area(N,a):` ` ` ` ` `# Formula to find sum of` ` ` `# Arithmetic Progression` ` ` `S ` `=` `N ` `*` `(a ` `+` `l) ` `/` `2` ` ` ` ` `# return area` ` ` `return` `S ` `*` `pi` `# N is number of concentric circles` `N ` `=` `100` `# Radius of interior circle` `a ` `=` `1` `# l radius of exterior circle` `l ` `=` `N` `# r is result` `r ` `=` `area(N, a)` `# Print result` `print` `(r)` |

## C#

`// C# program for the above approach` `using` `System;` `class` `GFG` `{` ` ` `// Function to calculate area` ` ` `// of concentric circles` ` ` `static` `double` `area(` `int` `N, ` `int` `a, ` `int` `l)` ` ` `{` ` ` `// Formula to find sum of` ` ` `// Arithmetic Progression` ` ` `double` `S = N * (a + l) / 2;` ` ` `// return area` ` ` `return` `S * Math.PI;` ` ` `}` ` ` `// Driver Code:` ` ` `public` `static` `void` `Main()` ` ` `{` ` ` `// N is number of concentric circles` ` ` `int` `N = 100;` ` ` `// Radius of interior circle` ` ` `int` `a = 1;` ` ` `// l radius of exterior circle` ` ` `int` `l = N;` ` ` `// r is result` ` ` `double` `r = area(N, a, l);` ` ` `// Print result` ` ` `Console.WriteLine(r);` ` ` `}` `}` `// This code is contributed by Samim Hossain Mondal.` |

## Javascript

`<script>` ` ` `// JavaScript code for the above approach` ` ` `// Function to calculate area` ` ` `// of concentric circles` ` ` `function` `area(N, a) {` ` ` `// Formula to find sum of` ` ` `// Arithmetic Progression` ` ` `S = N * (a + l) / 2` ` ` `// return area` ` ` `return` `S * Math.PI` ` ` `}` ` ` ` ` `// N is number of concentric circles` ` ` `N = 100` ` ` `// Radius of interior circle` ` ` `a = 1` ` ` `// l radius of exterior circle` ` ` `l = N` ` ` `// r is result` ` ` `r = area(N, a)` ` ` `// Print result` ` ` `document.write(r)` ` ` ` ` `// This code is contributed by Potta Lokesh` ` ` `</script>` |

**Output**

15865.042900628456

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