Statistics

Problem Statement for "Inchworm"

Problem Statement

The inchworm is a creature of regular habits. She inches forward some distance along the branch of a tree, then stops to rest. If she has stopped at a leaf, she makes a meal of it. Then she inches forward the same distance as before, and repeats this routine until she has reached or passed the end of the branch.

Consider an inchworm traveling the length of a branch whose leaves are spaced at uniform intervals. Depending on the distance between her resting points, the inchworm may or may not be able to eat all of the leaves. There is always a leaf at the beginning of the branch, which is where the inchworm rests before setting out on her journey.

You are given three int values that specify, in inches: the length of the branch; the distance traveled by the inchworm between rests; and the distance between each consecutive pair of leaves. Given that the inchworm only eats at rest, calculate the number of leaves she will consume.

Definition

Class:
Inchworm
Method:
lunchtime
Parameters:
int, int, int
Returns:
int
Method signature:
int lunchtime(int branch, int rest, int leaf)
(be sure your method is public)

Notes

  • The inchworm starts by gobbling up the leaf at the beginning of the branch.
  • If there is a leaf at the end of the branch, the inchworm eats it only if it falls at a resting point.

Constraints

  • branch is between 1 and 1000000 (one million), inclusive
  • rest is between 1 and 1000, inclusive
  • leaf is between 1 and 1000, inclusive

Examples

  1. 11

    2

    4

    Returns: 3

    Leaves grow 0, 4, and 8 inches from the beginning of the branch. The inchworm eats them all.

  2. 12

    6

    4

    Returns: 2

    The inchworm misses the leaves growing at distances 4 and 8, but eats those at 0 and 12.

  3. 20

    3

    7

    Returns: 1

    The inchworm eats only the leaf at the outset.

  4. 21

    7

    3

    Returns: 2

    The inchworm eats the leaves at the beginning and end of the branch.

  5. 15

    16

    5

    Returns: 1

    The inchworm eats only the leaf at the outset.

  6. 1000

    3

    7

    Returns: 48

  7. 1000

    7

    3

    Returns: 48

  8. 7872

    286

    64

    Returns: 1

  9. 17306

    139

    42

    Returns: 3

  10. 22207

    279

    86

    Returns: 1

  11. 31216

    912

    77

    Returns: 1

  12. 44450

    25

    27

    Returns: 66

  13. 50310

    3

    33

    Returns: 1525

  14. 68852

    172

    27

    Returns: 15

  15. 70175

    499

    82

    Returns: 2

  16. 87668

    819

    81

    Returns: 12

  17. 98020

    977

    28

    Returns: 4

  18. 103970

    534

    91

    Returns: 3

  19. 116737

    387

    25

    Returns: 13

  20. 126533

    462

    24

    Returns: 69

  21. 139739

    890

    93

    Returns: 2

  22. 141638

    102

    38

    Returns: 74

  23. 150112

    644

    26

    Returns: 18

  24. 168301

    60

    91

    Returns: 31

  25. 175599

    736

    7

    Returns: 35

  26. 186508

    537

    25

    Returns: 14

  27. 196965

    770

    52

    Returns: 10

  28. 203658

    459

    29

    Returns: 16

  29. 212006

    320

    10

    Returns: 663

  30. 220831

    980

    80

    Returns: 57

  31. 233971

    313

    94

    Returns: 8

  32. 242959

    117

    72

    Returns: 260

  33. 254069

    47

    46

    Returns: 118

  34. 266189

    595

    79

    Returns: 6

  35. 270824

    388

    95

    Returns: 8

  36. 288285

    606

    36

    Returns: 80

  37. 291959

    124

    61

    Returns: 39

  38. 308550

    620

    28

    Returns: 72

  39. 310109

    850

    26

    Returns: 29

  40. 328657

    98

    86

    Returns: 78

  41. 336738

    810

    14

    Returns: 60

  42. 348301

    131

    78

    Returns: 35

  43. 356116

    325

    51

    Returns: 22

  44. 364757

    319

    51

    Returns: 23

  45. 372894

    762

    24

    Returns: 123

  46. 387992

    247

    100

    Returns: 16

  47. 396711

    804

    83

    Returns: 6

  48. 408058

    327

    83

    Returns: 16

  49. 415448

    289

    93

    Returns: 16

  50. 428714

    275

    27

    Returns: 58

  51. 431027

    73

    68

    Returns: 87

  52. 440817

    675

    98

    Returns: 7

  53. 455523

    579

    70

    Returns: 12

  54. 463439

    197

    76

    Returns: 31

  55. 476703

    824

    67

    Returns: 9

  56. 486475

    646

    2

    Returns: 754

  57. 496412

    578

    92

    Returns: 19

  58. 508990

    78

    90

    Returns: 436

  59. 517569

    55

    509

    Returns: 19

  60. 527327

    81

    327

    Returns: 60

  61. 531784

    55

    329

    Returns: 30

  62. 546447

    59

    608

    Returns: 16

  63. 558890

    3

    933

    Returns: 600

  64. 565227

    31

    172

    Returns: 107

  65. 572565

    28

    692

    Returns: 119

  66. 587437

    49

    594

    Returns: 21

  67. 598465

    2

    873

    Returns: 343

  68. 608562

    49

    386

    Returns: 33

  69. 618186

    39

    502

    Returns: 32

  70. 621989

    27

    904

    Returns: 26

  71. 638644

    59

    506

    Returns: 22

  72. 649302

    63

    663

    Returns: 47

  73. 659709

    7

    11

    Returns: 8568

  74. 660314

    40

    812

    Returns: 82

  75. 673601

    61

    85

    Returns: 130

  76. 681181

    17

    479

    Returns: 84

  77. 692402

    42

    712

    Returns: 47

  78. 709292

    4

    348

    Returns: 2039

  79. 710104

    3

    154

    Returns: 1538

  80. 729917

    13

    341

    Returns: 165

  81. 734539

    95

    428

    Returns: 19

  82. 744435

    90

    743

    Returns: 12

  83. 756509

    60

    339

    Returns: 112

  84. 760805

    80

    994

    Returns: 20

  85. 772319

    33

    440

    Returns: 586

  86. 784781

    85

    288

    Returns: 33

  87. 796478

    14

    345

    Returns: 165

  88. 801670

    45

    293

    Returns: 61

  89. 815867

    51

    99

    Returns: 485

  90. 822467

    9

    688

    Returns: 133

  91. 835003

    29

    696

    Returns: 1200

  92. 840738

    31

    737

    Returns: 37

  93. 857463

    32

    118

    Returns: 455

  94. 867877

    49

    573

    Returns: 31

  95. 875741

    98

    638

    Returns: 29

  96. 883104

    90

    881

    Returns: 12

  97. 899002

    11

    936

    Returns: 88

  98. 906502

    86

    315

    Returns: 34

  99. 918346

    53

    573

    Returns: 31

  100. 926058

    23

    76

    Returns: 530

  101. 10

    2

    2

    Returns: 6

  102. 10

    1

    1

    Returns: 11

  103. 1000

    1

    1

    Returns: 1001

  104. 4

    3

    2

    Returns: 1

  105. 1000000

    1

    1

    Returns: 1000001


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: