Statistics

Problem Statement for "FunctionIter"

Problem Statement

*** You may only submit a given problem once - no resubmissions will be accepted. ***

You will be given a int[] f describing a function (0-indexed). The value of the function on input k is f[k] (element k of f). To iterate a function you keep calling it on itself. For example, to iterate f 5 times on input x, you would evaluate
     f(f(f(f(f(x))))).    
Return the smallest number n larger than bound, such that iterating f n times on x evaluates to x.

Definition

Class:
FunctionIter
Method:
compute
Parameters:
int[], int, int
Returns:
int
Method signature:
int compute(int[] f, int bound, int x)
(be sure your method is public)

Constraints

  • f will contain between 1 and 50 elements inclusive.
  • Each element of f will be between 0 and k-1 inclusive, where k is the number of elements in f.
  • bound will be between 0 and 10000 inclusive.
  • x will be between 0 and k-1 inclusive, where k is the number of elements in f.
  • There will be a solution.

Examples

  1. {0,1,2,3,4,5}

    2

    4

    Returns: 3

    Everything is mapped to itself by f. Simply return the first value after bound.

  2. {1,2,3,4,5,6,0}

    3

    1

    Returns: 7

    1->2->3->4->5->6->0->1 7 steps needed to return to 1.

  3. {9,9,4,4,5,6,7,18,7,10,3,4,2,8,1,3,12,3,1,1,0,0,0}

    784

    9

    Returns: 792

  4. {0}

    10000

    0

    Returns: 10001

  5. {0}

    0

    0

    Returns: 1

  6. {3,7,47,42,4,35,11,43,30,25,38,11,25,17,38,35,45,30,42,0,26,27,26,39,45,4,26,15,44,17,32,9,24,21,47,14,47,12,46,6,22,16,3,33,30,18,48,47,5,2}

    4305

    14

    Returns: 4308

  7. {26,8,26,37,20,2,41,6,12,16,7,31,48,29,27,21,34,28,10,35,0,49,19,38,25,33,10,48,36,28,26,32,10,3,14,13,19,8,22,34,19,18,13,4,36,43,42,29,28,11}

    2641

    10

    Returns: 2645

  8. {27,36,29,46,40,39,41,8,11,33,30,31,5,49,25,22,5,45,9,9,30,19,5,13,6,32,35,27,29,16,45,18,8,43,6,21,31,33,21,11,28,48,5,18,16,29,0,49,17,22}

    7148

    33

    Returns: 7152

  9. {19,5,46,7,12,19,42,17,30,45,26,31,22,48,44,23,17,1,26,42,6,3,6,34,49,22,22,10,27,33,35,43,44,4,19,11,46,38,32,2,16,31,13,32,2,7,44,13,21,41}

    4789

    13

    Returns: 4790

  10. {19,12,3,11,35,20,31,13,11,38,39,13,46,24,40,47,0,31,44,23,40,9,24,12,0,33,20,14,34,6,22,31,13,4,45,33,1,32,47,39,7,27,27,46,25,49,2,34,42,20}

    8802

    19

    Returns: 8810

  11. {35,25,3,18,5,10,31,19,24,46,24,21,32,19,34,48,41,5,14,32,15,49,2,7,30,48,44,14,46,18,25,36,24,46,42,2,34,46,5,41,41,14,12,23,38,38,32,32,16,10}

    4317

    42

    Returns: 4323

  12. {46,20,7,17,40,29,19,44,0,39,16,5,49,40,45,30,47,30,23,12,43,42,5,12,15,47,13,9,22,29,42,7,47,31,31,25,10,3,14,7,38,42,15,10,30,5,32,26,15,36}

    195

    15

    Returns: 198

  13. {45,12,48,20,4,22,27,17,47,33,8,31,6,1,40,7,39,26,4,19,12,12,4,15,1,10,27,49,38,38,36,40,38,38,33,8,32,13,0,46,12,22,43,29,36,36,49,6,31,32}

    4210

    4

    Returns: 4211

  14. {30,28,12,16,23,40,34,1,0,46,42,27,25,41,36,35,17,19,25,7,24,15,42,19,43,48,9,35,48,5,49,36,36,30,8,41,37,32,17,42,1,43,4,29,47,32,22,44,11,37}

    1009

    28

    Returns: 1012

  15. {32,42,39,5,43,31,21,8,3,28,27,27,22,35,18,41,7,29,27,4,19,7,31,26,16,11,43,28,17,33,14,38,34,18,18,21,23,23,41,22,27,35,39,43,49,0,17,25,26,26}

    211

    8

    Returns: 216

  16. {3,11,45,38,27,26,28,32,44,16,2,19,40,29,3,38,5,7,27,31,7,38,19,11,22,5,49,8,6,15,44,28,47,42,37,42,37,29,37,25,40,46,11,43,34,4,49,18,33,1}

    3115

    29

    Returns: 3116

  17. {36,40,6,31,0,1,12,46,5,33,25,15,23,32,3,35,43,17,1,20,15,48,35,0,16,40,17,25,10,48,34,17,18,12,19,43,27,15,24,30,9,17,15,38,22,33,25,14,8,48}

    4078

    36

    Returns: 4086

  18. {27,15,10,3,27,41,27,49,42,13,35,47,49,43,0,8,0,25,20,11,6,9,36,9,11,2,43,23,41,42,5,22,35,45,39,7,10,36,17,49,32,44,47,48,29,34,4,7,46,27}

    4048

    46

    Returns: 4056

  19. {47,29,38,16,39,36,19,47,49,10,0,11,25,5,41,6,26,39,5,12,21,13,20,27,30,16,1,20,15,18,16,16,32,43,6,10,8,27,17,4,4,22,23,10,14,4,13,0,17,20}

    3305

    36

    Returns: 3311

  20. {42,41,27,7,19,9,16,6,18,25,46,6,6,19,34,23,21,2,49,40,11,12,14,30,1,43,19,38,29,27,32,10,21,45,48,34,30,2,6,12,40,45,20,30,7,44,45,48,17,21}

    3982

    16

    Returns: 3984

  21. {16,16,34,8,7,33,32,46,6,26,19,3,31,9,24,7,20,10,6,7,4,36,8,25,42,13,46,44,16,46,34,46,25,1,21,18,31,6,36,35,30,2,29,48,22,3,18,2,47,40}

    3208

    18

    Returns: 3216

  22. {39,32,49,40,21,21,1,6,19,46,29,19,11,15,3,35,8,35,5,5,23,46,45,5,14,7,7,45,3,9,15,35,46,13,48,23,3,17,38,25,46,48,35,34,5,25,34,14,4,5}

    1520

    46

    Returns: 1525

  23. {9,43,45,13,16,32,2,11,12,2,13,29,43,43,6,27,24,1,22,21,0,11,39,34,29,20,2,21,28,5,20,7,0,6,35,44,38,24,49,29,6,1,6,27,18,27,9,15,2,10}

    3719

    29

    Returns: 3720

  24. {29,34,21,29,0,33,28,44,26,31,47,22,11,48,30,27,8,35,48,12,21,21,22,34,36,49,10,13,29,39,49,17,41,13,17,8,29,30,48,0,31,5,15,31,0,42,40,41,36,28}

    8656

    22

    Returns: 8657

  25. {13,0,45,48,44,11,7,34,40,30,2,30,37,38,29,26,7,29,23,43,28,26,34,21,17,49,37,22,41,37,1,45,4,6,45,22,37,47,23,1,13,5,7,47,49,46,11,39,38,11}

    4713

    23

    Returns: 4720

  26. {28,13,6,40,38,49,11,8,11,6,21,31,40,35,14,2,49,4,31,10,34,27,6,32,17,10,33,40,27,34,10,22,42,31,25,28,40,24,11,36,33,30,36,45,35,19,7,6,16,25}

    8847

    22

    Returns: 8848

  27. {39,12,0,41,3,20,0,28,10,37,44,19,32,37,1,8,25,33,6,6,4,7,8,36,21,48,5,30,23,12,26,17,29,22,21,20,27,7,32,4,24,2,5,6,7,10,25,49,48,19}

    5472

    48

    Returns: 5473

  28. {40,28,22,10,44,45,49,10,39,2,27,42,14,3,38,13,39,20,14,45,35,10,34,7,38,17,42,30,24,1,1,45,6,36,18,0,44,1,36,11,3,48,14,39,6,13,31,5,5,47}

    5944

    3

    Returns: 5952

  29. {46,22,12,35,31,48,42,26,41,33,38,38,7,5,29,18,9,17,4,29,5,21,49,41,19,12,47,33,27,33,42,12,27,48,14,34,31,16,11,1,43,46,41,25,47,15,41,2,38,25}

    4137

    17

    Returns: 4138

  30. {35,5,7,9,39,42,22,17,22,47,48,48,32,39,10,47,23,46,13,10,0,38,12,9,31,15,31,24,20,8,28,23,37,40,4,40,37,2,3,15,15,20,13,36,47,27,6,15,26,45}

    1144

    37

    Returns: 1152

  31. {47,35,5,49,31,14,46,27,22,39,19,8,22,16,19,35,49,3,1,20,38,40,14,2,42,17,18,21,26,38,41,4,24,46,22,13,42,34,28,34,7,15,12,35,49,38,24,14,33,18}

    1111

    18

    Returns: 1116

  32. {47,26,33,30,24,2,14,36,28,27,49,46,4,37,36,34,17,12,2,28,16,49,37,15,32,39,25,44,43,0,11,22,33,47,14,12,12,46,23,6,8,9,32,11,41,27,37,22,48,32}

    6718

    41

    Returns: 6720

  33. {5,4,21,35,19,33,15,6,33,4,8,14,15,6,12,2,49,19,26,38,18,29,13,15,2,21,26,27,9,16,18,29,26,17,29,22,40,7,10,6,25,8,36,47,18,14,47,47,31,28}

    4089

    33

    Returns: 4092

  34. {33,43,19,38,40,34,22,34,25,16,24,8,8,13,2,26,31,24,9,0,42,22,8,5,17,9,35,49,28,23,43,25,35,19,36,25,31,31,24,23,13,48,23,25,16,33,21,39,45,9}

    6437

    0

    Returns: 6438

  35. {21,7,46,15,23,27,1,0,4,33,29,48,15,37,1,0,31,25,41,24,47,2,14,20,46,6,34,49,39,24,33,29,27,10,29,33,27,21,15,43,5,22,10,20,19,30,19,5,23,1}

    2882

    46

    Returns: 2883

  36. {13,45,20,29,3,30,34,31,37,48,25,27,10,40,16,47,7,32,20,39,36,26,37,42,8,32,45,21,16,12,41,24,2,47,39,4,0,29,5,29,1,28,25,22,48,5,10,14,45,44}

    7016

    36

    Returns: 7038

  37. {15,25,37,16,17,38,19,4,40,17,9,36,39,29,24,23,7,0,5,35,26,46,23,32,16,2,14,17,12,7,43,39,43,0,6,5,42,13,47,44,39,2,34,36,46,36,41,26,11,3}

    1680

    17

    Returns: 1701

  38. {2,17,5,42,41,41,5,37,4,19,46,9,14,43,44,27,18,25,30,18,8,33,28,24,0,15,18,35,9,24,33,47,13,7,11,45,39,3,28,13,10,48,39,14,24,11,42,31,17,16}

    6916

    25

    Returns: 6939

  39. {4,47,23,31,34,47,20,35,29,17,13,8,47,4,18,49,47,49,44,28,29,39,14,24,27,39,41,46,27,6,7,10,34,30,19,43,1,49,49,14,9,1,9,3,24,33,36,38,21,45}

    1932

    43

    Returns: 1953

  40. {6,22,48,0,45,22,17,5,14,3,47,31,26,47,37,9,40,14,4,15,42,46,20,8,21,1,35,16,16,22,25,12,31,25,24,48,29,43,31,18,34,13,11,28,7,35,33,14,9,4}

    2161

    0

    Returns: 2187

  41. {35,5,30,6,21,9,3,32,34,15,34,21,10,44,30,23,35,25,32,30,34,22,1,43,23,8,38,28,21,47,36,2,38,28,31,39,32,0,0,46,36,15,13,8,35,22,48,1,33,46}

    6855

    36

    Returns: 6877

  42. {16,10,11,17,21,46,3,22,34,43,12,45,11,25,47,44,28,48,5,29,8,7,33,36,21,25,14,38,6,16,47,36,42,19,46,24,6,0,4,9,40,40,46,46,13,9,26,35,39,7}

    9556

    6

    Returns: 9576

  43. {10,12,27,21,34,27,38,26,17,14,43,35,43,36,36,27,21,22,30,3,1,22,31,47,44,22,9,33,25,21,0,4,46,11,27,44,46,47,33,30,11,33,1,47,18,32,28,45,16,20}

    5640

    18

    Returns: 5660

  44. {24,32,49,2,14,13,25,46,15,29,8,26,5,29,18,34,44,49,0,17,15,48,38,4,47,31,44,42,46,35,32,27,41,21,38,32,47,16,16,11,43,23,10,33,12,29,41,25,35,20}

    800

    12

    Returns: 825

  45. {37,19,4,28,10,19,49,34,9,47,31,16,11,5,43,24,3,12,26,6,22,8,22,19,16,24,41,49,9,43,23,41,20,49,48,44,46,34,2,27,5,17,43,32,13,7,33,37,5,38}

    3256

    5

    Returns: 3276

  46. {38,4,33,40,13,41,9,25,48,30,31,31,11,14,29,43,35,28,35,19,6,11,21,21,3,23,35,22,38,40,1,20,23,30,34,11,46,16,25,28,45,15,5,44,27,42,8,34,48,12}

    3300

    29

    Returns: 3322

  47. {23,3,23,37,12,27,4,49,26,37,33,45,20,45,30,32,26,16,21,20,34,6,42,21,20,45,29,49,45,14,1,39,47,36,32,39,23,41,37,41,27,40,4,21,37,16,31,17,38,43}

    440

    29

    Returns: 462

  48. {40,41,15,0,23,2,22,46,15,31,2,4,13,24,26,11,47,49,17,6,36,34,8,9,1,2,28,3,3,29,10,36,12,27,1,24,26,36,40,32,35,46,15,30,27,33,18,48,38,30}

    9937

    0

    Returns: 9959

  49. {36,35,40,26,3,46,11,46,46,36,1,36,34,19,30,48,45,7,11,33,49,42,17,25,25,12,30,4,28,12,18,16,17,37,4,13,15,29,24,17,15,20,39,35,36,41,43,15,21,34}

    8762

    4

    Returns: 8784

  50. {46,13,42,31,7,40,41,2,2,34,13,9,10,37,19,8,5,10,33,7,10,25,38,18,23,30,26,13,21,49,39,6,47,28,27,2,47,5,31,20,22,7,0,11,14,11,18,6,31,21}

    9018

    6

    Returns: 9039

  51. {12,4,7,10,6,29,21,16,11,7,44,17,34,42,34,43,6,40,14,40,32,14,44,4,9,25,46,4,9,3,6,16,48,41,8,26,13,42,33,39,33,29,24,46,36,6,23,8,38,45}

    4138

    9

    Returns: 4158

  52. {27,45,8,29,5,27,1,30,33,33,42,20,38,3,43,49,42,2,3,26,35,0,15,19,37,31,23,14,44,36,31,44,9,4,3,30,20,9,42,8,32,19,37,18,45,22,25,8,29,17}

    3455

    36

    Returns: 3476

  53. {0,39,13,14,47,31,34,9,41,13,4,46,10,1,3,43,25,19,27,3,32,26,30,33,33,28,11,20,34,37,41,22,23,35,33,38,5,45,29,5,6,16,37,25,35,21,9,39,9,18}

    3131

    22

    Returns: 3151

  54. {11,8,47,12,35,3,47,48,9,12,0,17,14,23,41,34,26,42,30,6,32,10,38,6,33,33,36,15,13,29,4,39,1,0,16,32,16,6,35,49,13,7,43,37,4,9,27,30,24,29}

    2465

    30

    Returns: 2486

  55. {22,8,18,30,16,15,30,12,0,14,5,10,43,46,33,38,4,34,43,2,31,0,9,44,20,38,6,14,31,27,18,11,14,7,6,46,39,14,36,47,35,13,27,28,48,3,27,23,41,38}

    3676

    47

    Returns: 3696

  56. {46,33,5,19,45,23,33,35,9,10,40,9,45,16,12,17,8,46,2,16,48,28,30,43,49,28,33,49,24,44,42,18,32,20,16,23,37,46,15,41,14,1,39,17,41,43,39,14,21,34}

    2772

    14

    Returns: 2794

  57. {22,43,49,15,37,8,36,40,12,2,4,6,25,37,15,33,45,0,49,7,47,7,28,35,47,1,1,12,2,29,30,45,46,5,2,31,3,14,41,40,46,10,16,24,38,38,0,7,37,10}

    177

    5

    Returns: 198

  58. {0,3,28,43,35,33,34,41,17,49,18,5,47,46,10,1,27,19,25,32,45,48,12,5,7,44,15,3,13,0,23,10,39,8,26,15,26,7,36,27,21,45,24,22,30,14,44,45,35,0}

    1786

    3

    Returns: 1806

  59. {47,37,4,22,43,4,11,47,45,11,25,17,2,43,28,23,1,33,47,42,38,41,48,0,10,23,37,30,7,34,9,2,25,20,36,48,7,26,46,27,24,3,39,9,13,34,40,35,12,12}

    4040

    46

    Returns: 4060

  60. {15,44,27,31,17,28,33,40,46,40,5,17,24,16,8,37,3,9,30,5,14,6,41,21,16,25,24,23,29,11,19,39,6,45,31,10,5,48,28,44,23,3,11,22,5,47,20,43,44,40}

    3640

    40

    Returns: 3660

  61. {42,19,35,2,39,28,42,22,30,4,31,48,47,1,33,11,7,32,6,16,15,27,9,43,7,16,10,24,3,43,41,40,0,17,1,40,5,30,27,5,46,20,34,8,46,44,33,32,20,36}

    3213

    33

    Returns: 3234

  62. {38,14,13,9,36,36,25,17,8,28,3,25,44,31,27,49,39,15,43,6,3,33,10,24,11,3,40,46,34,21,4,35,38,23,14,40,6,7,31,11,29,20,12,45,18,19,37,29,32,2}

    4801

    15

    Returns: 4824

  63. {3,0,41,49,31,15,45,46,12,18,24,39,47,36,13,16,39,28,28,7,14,35,12,37,1,41,3,4,32,19,3,6,31,40,14,27,29,12,42,25,5,12,45,10,45,25,17,10,46,20}

    4588

    3

    Returns: 4608

  64. {7,36,12,6,47,6,12,9,18,19,7,16,14,42,45,25,3,42,46,24,22,41,26,29,49,0,15,11,1,27,23,5,26,30,33,20,43,6,44,29,35,5,40,26,0,17,17,7,21,27}

    7383

    25

    Returns: 7406

  65. {23,14,1,40,47,27,28,48,44,19,23,0,48,25,9,18,39,6,13,49,10,17,21,31,43,27,14,41,48,49,1,45,20,31,30,42,17,32,20,4,10,22,9,27,21,34,41,36,40,18}

    3059

    30

    Returns: 3082


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: