Calculating the number π using the Monte Carlo method with a given accuracy
Kotlin
Hard
math
Task «Calculating the number π using the Monte Carlo method with a given accuracy»
It is necessary to compute an approximate value of π using the Monte Carlo method. To do this, points are randomly generated in a square with side length 2 (from -1 to 1 on each axis). The fraction of points that fall inside a circle of radius 1, multiplied by 4, gives an estimate of π. The calculation accuracy is determined by the number of points N (an integer from 10^6 to 10^9). Output the value of π with an accuracy of 6 decimal places.
Input Format
One integer N (10^6 ≤ N ≤ 10^9) — the number of random points.
Output Format
One real number — an approximate value of π, rounded to 6 decimal places.
main.kt