Sum of area of alternative concentric circle with radius 1,2,3,4……….N
Last Updated :
20 Jan, 2022
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=100
Output: 15865.042900628456
Input: N=10
Output: 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-
SN = N * (2 * a +(N – 1) * d) / 2
or
SN = N * (a + l) / 2
Thus, the area of the green region is-
A = Sn * ?
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
double area( int N, int a, int l)
{
double S = N * (a + l) / 2;
return S * M_PI;
}
int main()
{
int N = 100;
int a = 1;
int l = N;
double r = area(N, a, l);
cout << fixed << setprecision(12) << r;
}
|
Java
class GFG
{
static double area( int N, int a, int l)
{
double S = N * (a + l) / 2 ;
return S * Math.PI;
}
public static void main(String args[])
{
int N = 100 ;
int a = 1 ;
int l = N;
double r = area(N, a, l);
System.out.println(r);
}
}
|
Python3
from math import pi
def area(N,a):
S = N * (a + l) / 2
return S * pi
N = 100
a = 1
l = N
r = area(N, a)
print (r)
|
C#
using System;
class GFG
{
static double area( int N, int a, int l)
{
double S = N * (a + l) / 2;
return S * Math.PI;
}
public static void Main()
{
int N = 100;
int a = 1;
int l = N;
double r = area(N, a, l);
Console.WriteLine(r);
}
}
|
Javascript
<script>
function area(N, a) {
S = N * (a + l) / 2
return S * Math.PI
}
N = 100
a = 1
l = N
r = area(N, a)
document.write(r)
</script>
|
Output
15865.042900628456
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...