Count pieces of circle after N cuts
Given an integer N, where . The task is to print the count of pieces of a circle with N cuts where each cut passes through the centre of given circle.
Examples:
Input : N = 2
Output : 4
Input : N = 100
Output : 200
Approach: This problem can be easily solved with observation only. Since each cut passes through the centre, each cut creates two new pieces.
Let us see how above Intuition works.
- At first cut we have 2 different pieces of circle.
- At second cut we have 2 new different pieces from previous 2 pieces of circle.
- At third cut we have again 2 new different pieces from any of previous 2 pieces which are opposite to each other.
In this way, we proceed with N cuts to get the count of total pieces after N cuts.
Below is the implementation of above approach:
C++
#include <bits/stdc++.h>
using namespace std;
int countPieces( int N)
{
return 2 * N;
}
int main()
{
int N = 100;
cout << countPieces(N);
return 0;
}
|
Java
import java.util.*;
class solution
{
static int countPieces( int N)
{
return 2 * N;
}
public static void main(String args[])
{
int N = 100 ;
System.out.println(countPieces(N));
}
}
|
Python3
def countPieces(N):
return 2 * N
N = 100
print (countPieces(N))
|
C#
class solution
{
static int countPieces( int N)
{
return 2 * N;
}
static void Main()
{
int N = 100;
System.Console.WriteLine(countPieces(N));
}
}
|
PHP
<?php
function countPieces( $N )
{
return 2 * $N ;
}
$N = 100;
echo countPieces( $N );
?>
|
Javascript
<script>
function countPieces(N)
{
return 2 * N;
}
let N = 100;
document.write(countPieces(N));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
11 Jul, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...