Statistics

Problem Statement for "FarmFence"

Problem Statement

Your friend, John, is a poor farmer living in the rural area. Each year, he has to produce a certain amount of crops in order to support his family of five.

One unit of crops can be produced from a 1 by 1 square of farm land. John needs to protect his farm from intruders and animals by putting barbed wire fences along the boundary of the farm. Being so poor, John wants to minimize the length of the fence he has to purchase to protect his farm. John can change the shape of his farm to any rectangle with integral width and height in order to achieve this minimal fencing. He turns to you for help.

You are given the amount of crops that John needs to produce each year. Your task is to write a function that returns the minimum length of barbed wire fence needed to protect John's farm. The farm must have exactly the area required to produce the amount of crops specified and must be a rectangle with integral length sides.

Definition

Class:
FarmFence
Method:
minFencing
Parameters:
int
Returns:
int
Method signature:
int minFencing(int crops)
(be sure your method is public)

Constraints

  • crops is between 1 and 1,000,000, inclusive

Examples

  1. 6

    Returns: 10

    The possible dimensions of the farm are 1x6 and 2x3 (ignoring rotations). The amount of fencing is 14 for 1x6 and 10 for 2x3. 10 is the minimum.

  2. 18

    Returns: 18

    The possible dimensions are 1x18, 2x9, and 3x6 (ignoring rotations). The required fencing are 38, 22, and 18, respectively. 18 is the minimum.

  3. 987

    Returns: 136

  4. 123456

    Returns: 1670

  5. 1000000

    Returns: 4000

  6. 999983

    Returns: 1999968

  7. 667

    Returns: 104

  8. 687

    Returns: 464

  9. 533

    Returns: 108

  10. 332

    Returns: 174

  11. 235

    Returns: 104

  12. 680

    Returns: 108

  13. 274

    Returns: 278

  14. 799

    Returns: 128

  15. 134

    Returns: 138

  16. 298

    Returns: 302

  17. 469

    Returns: 148

  18. 586

    Returns: 590

  19. 992

    Returns: 126

  20. 487

    Returns: 976

  21. 349

    Returns: 700

  22. 186

    Returns: 74

  23. 567

    Returns: 96

  24. 564

    Returns: 118

  25. 254

    Returns: 258

  26. 931

    Returns: 136

  27. 89

    Returns: 180

  28. 11

    Returns: 24

  29. 707

    Returns: 216

  30. 662

    Returns: 666

  31. 556

    Returns: 286

  32. 944220

    Returns: 31594

  33. 821337

    Returns: 49844

  34. 653048

    Returns: 3252

  35. 150682

    Returns: 1574

  36. 472766

    Returns: 67566

  37. 304379

    Returns: 11592

  38. 6297

    Returns: 4204

  39. 134427

    Returns: 89624

  40. 174702

    Returns: 5426

  41. 474513

    Returns: 2852

  42. 216264

    Returns: 18070

  43. 1687

    Returns: 496

  44. 218176

    Returns: 1870

  45. 40027

    Returns: 6184

  46. 548923

    Returns: 11512

  47. 982845

    Returns: 43772

  48. 758018

    Returns: 758022

  49. 323890

    Returns: 2302

  50. 741497

    Returns: 5364

  51. 874317

    Returns: 582884

  52. 92054

    Returns: 92058

  53. 639413

    Returns: 5292

  54. 993074

    Returns: 15090

  55. 699491

    Returns: 8616

  56. 991771

    Returns: 6856

  57. 1

    Returns: 4

  58. 3

    Returns: 8

  59. 2

    Returns: 6

  60. 1

    Returns: 4

  61. 1000000

    Returns: 4000

  62. 17

    Returns: 36

  63. 999998

    Returns: 8382

  64. 14

    Returns: 18

  65. 99991

    Returns: 199984

  66. 4

    Returns: 8

  67. 5

    Returns: 12

  68. 10

    Returns: 14

  69. 6

    Returns: 10

  70. 20

    Returns: 18


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: