Algorithm
Problem Name: beecrowd | 2802
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2802
Dividing Circles
By Francisco Elio Parente Arcos Filho, UEA Brazil
Timelimit: 1
Given a set of N points on a circumference of a circle, every pair of points is connected by a segment and three of those segments never cross each other in a point inside the circumference.
Your task is to determine in how many parts these segments divide the interior of the circle.
Input
The first and only line of the input contains an integer N (1 ≤ N ≤ 1000) representing the number of points on the circumference.
Output
The output consists of a single line containing an integer representing the number of parts of the circle.
Input Samples | Output Samples |
1 |
1 |
2 |
2 |
3 |
4 |
4 |
8 |
5 |
16 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#include <math.h>
int main() {
double N, resposta;
scanf("%lf", &N);
resposta = (pow(N, 4.0) - (6.0 * pow(N, 3.0)) + (23.0 * pow(N, 2.0)) - (18.0 * N) + 24.0 ) / 24.0;
printf("%.0lf\n", resposta);
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("node:fs")
const [input] = readFileSync("/dev/stdin", "utf8")
.split("\n", 1)
.map(value => Number.parseInt(value, 10))
const R = (n = 0) => 1 + (n * (n - 1) * (12 + (n - 2) * (n - 3))) / 24
console.log(R(input))
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Python Programming
Code -
Python Programming
n = int(input())
n = ((n/24.0)*(n*n*n - 6*n*n + 23*n - 18)) + 1
print("%.0f" % n)
Copy The Code &
Try With Live Editor
Input
Output