Statistics

Problem Statement for "RecursiveFigures"

Problem Statement

Draw a square with side length sideLength on a plane. Then, inscribe a circle in the square. Inscribe another square in that circle, and yet another circle in the second square. Continue this process until K circles appear on the plane.

For example, if K=3, the picture would look like this:

For each circle, compute the area within the circle that does not belong to any other figure inside that circle. Return the sum of those areas. In the example above, the area to compute is colored in stripes.

Definition

Class:
RecursiveFigures
Method:
getArea
Parameters:
int, int
Returns:
double
Method signature:
double getArea(int sideLength, int K)
(be sure your method is public)

Notes

  • Your return value must have an absolute or relative error less than 1e-9.
  • The area of square with side length A is A*A.
  • The area of circle with radius R is pi*R*R.
  • The length of diameter of the circle inscribed in a square is equal to the square's side length.
  • The side length of the square inscribed in circle with radius R is equal to R*sqrt(2).

Constraints

  • sideLength will be between 1 and 100, inclusive.
  • K will be between 1 and 10, inclusive.

Examples

  1. 10

    1

    Returns: 78.53981633974483

  2. 10

    2

    Returns: 67.80972450961724

  3. 10

    3

    Returns: 62.444678594553444

  4. 1

    4

    Returns: 0.5976215563702155

  5. 7

    7

    Returns: 28.133324544098755

  6. 9

    6

    Returns: 46.77771336928683

  7. 16

    7

    Returns: 146.9822670059037

  8. 18

    4

    Returns: 193.62938426394982

  9. 19

    7

    Returns: 207.26796245754392

  10. 21

    5

    Returns: 257.6361432379073

  11. 23

    6

    Returns: 305.4988934858362

  12. 23

    9

    Returns: 302.39471145091727

  13. 28

    7

    Returns: 450.1331927055801

  14. 32

    2

    Returns: 694.3715789784806

  15. 41

    8

    Returns: 962.3269510244776

  16. 44

    2

    Returns: 1312.7962665061896

  17. 44

    4

    Returns: 1156.995333132737

  18. 45

    2

    Returns: 1373.1469213197493

  19. 45

    7

    Returns: 1162.6526979959183

  20. 47

    7

    Returns: 1268.2962024064113

  21. 47

    9

    Returns: 1262.7408650190475

  22. 50

    2

    Returns: 1695.2431127404311

  23. 51

    2

    Returns: 1763.7309344951445

  24. 52

    2

    Returns: 1833.57495074005

  25. 52

    7

    Returns: 1552.5001952498578

  26. 53

    1

    Returns: 2206.1834409834323

  27. 53

    8

    Returns: 1608.0763863341815

  28. 54

    2

    Returns: 1977.3315667004385

  29. 55

    1

    Returns: 2375.8294442772813

  30. 55

    6

    Returns: 1746.9454684208972

  31. 63

    8

    Returns: 2272.144954560472

  32. 65

    3

    Returns: 2638.2876706198836

  33. 66

    5

    Returns: 2544.8141495336145

  34. 67

    6

    Returns: 2592.4093248731915

  35. 69

    8

    Returns: 2725.5434942460074

  36. 72

    10

    Returns: 2961.1810017003445

  37. 76

    4

    Returns: 3451.862109594365

  38. 78

    1

    Returns: 4778.362426110075

  39. 79

    8

    Returns: 3572.8033916381723

  40. 80

    8

    Returns: 3663.8265833174655

  41. 89

    7

    Returns: 4547.838034975638

  42. 89

    8

    Returns: 4534.557869759006

  43. 91

    6

    Returns: 4782.299313716843

  44. 94

    10

    Returns: 5047.259901817948

  45. 96

    7

    Returns: 5291.361612212533

  46. 98

    10

    Returns: 5485.953383551331

  47. 100

    8

    Returns: 5724.7290364335395

  48. 100

    10

    Returns: 5712.154710070109

  49. 99

    10

    Returns: 5598.482831339714

  50. 1

    10

    Returns: 0.5712154710070109

  51. 100

    1

    Returns: 7853.981633974483

  52. 99

    9

    Returns: 5602.590863762646

  53. 99

    5

    Returns: 5725.831836450631

  54. 9

    2

    Returns: 54.92587685278996

  55. 3

    1

    Returns: 7.0685834705770345

  56. 1

    1

    Returns: 0.7853981633974483

  57. 1

    3

    Returns: 0.6244467859455345

  58. 7

    10

    Returns: 27.98955807934353

  59. 20

    3

    Returns: 249.77871437821378

  60. 100

    7

    Returns: 5741.494804918114

  61. 9

    5

    Returns: 47.320924268187035

  62. 50

    5

    Returns: 1460.5223539563901

  63. 2

    10

    Returns: 2.2848618840280435

  64. 27

    10

    Returns: 416.4160783641109


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: