Statistics

Problem Statement for "FewestFactors"

Problem Statement

You will be given some decimal digits in a int[] digits. Build an integer with the minimum possible number of factors, using each of the digits exactly once (be sure to count all factors, not only the prime factors). If more than one number has the same (minimum) number of factors, return the smallest one among them.

Definition

Class:
FewestFactors
Method:
number
Parameters:
int[]
Returns:
int
Method signature:
int number(int[] digits)
(be sure your method is public)

Notes

  • A factor of an integer n is an integer k, such that n % k = 0 (% being the modulo operator).
  • The digit 0 can also be used as a leading zero, see example 1.

Constraints

  • digits will have between 1 and 5 elements, inclusive.
  • Each element of digits will be between 0 and 9, inclusive.
  • At least one element of digits will be non-zero.

Examples

  1. {1, 2}

    Returns: 21

    Using the digits 1 and 2 we can build the numbers 12 (which has 6 factors: 1, 2, 3, 4, 6 and 12) and 21 (which has 4 factors: 1, 3, 7 and 21). So we return 21, which is the number among them having the smallest number of factors.

  2. {6, 0}

    Returns: 6

    Note that we can use 0 as a leading zero, giving the number 6 that has 4 factors (1, 2, 3 and 6), less than the alternative 60 that has 12 factors.

  3. {4, 7, 4}

    Returns: 447

    Note that digits may contain duplicate digits. We have to use each digit as many times as it appears in the input.

  4. {1, 3, 7, 9}

    Returns: 1973

  5. {7, 5, 4, 3, 6}

    Returns: 36457

  6. {1}

    Returns: 1

  7. {8}

    Returns: 8

  8. {9}

    Returns: 9

  9. {0, 0, 0, 0, 1}

    Returns: 1

  10. {0, 1}

    Returns: 1

  11. {0, 6}

    Returns: 6

  12. {2, 4}

    Returns: 24

    Both 24 and 42 have 8 factors (24 has the factors 1, 2, 3, 4, 6, 8, 12 and 24, while 42 has the factors 1, 2, 3, 6, 7, 14, 21 and 42). In this case we have to use the tie-breaker and return

  13. {2, 6}

    Returns: 26

  14. {8, 1}

    Returns: 81

  15. {0, 1, 0}

    Returns: 1

  16. {0, 2, 4}

    Returns: 24

  17. {2, 3, 4}

    Returns: 243

  18. {3, 4, 3}

    Returns: 433

  19. {1, 1, 2}

    Returns: 211

  20. {2, 5, 9}

    Returns: 529

  21. {4, 4, 8}

    Returns: 844

  22. {9, 8, 7}

    Returns: 789

  23. {3, 3, 1, 1}

    Returns: 1133

  24. {1, 2, 3, 4}

    Returns: 1423

  25. {2, 4, 6, 8}

    Returns: 2846

  26. {1, 3, 7, 9}

    Returns: 1973

  27. {0, 4, 8, 6, 2}

    Returns: 2846

  28. {2, 4, 6, 8, 1}

    Returns: 24861

  29. {9, 8, 7, 6, 5}

    Returns: 56897

  30. {8, 6, 5, 1, 7}

    Returns: 16857

  31. {0, 3, 0, 0, 0}

    Returns: 3

  32. {2, 2, 2, 2, 2}

    Returns: 22222

  33. {4, 4, 4, 4, 1}

    Returns: 44441

  34. {1, 3, 3, 3, 3}

    Returns: 31333

  35. {1,2,4}

    Returns: 241

    Both 241 and 421 are prime numbers, and thus have exactly 2 factors (241 has the factors 1 and 241, while 421 has the factors 1 and 421). All other numbers that we can build from these digits (124, 142, 214 and 412) have more than 2 factors. We have to use the tie-breaker here and return the smaller of (241, 421).

  36. {6, 0, 4}

    Returns: 46

  37. {8, 3, 2, 6, 9}

    Returns: 23689

  38. {1, 7, 1, 5}

    Returns: 1571

  39. {9, 6, 0}

    Returns: 69

  40. {9, 3, 7, 5, 8}

    Returns: 35879

  41. {4, 6, 8}

    Returns: 486

  42. {2, 8, 1}

    Returns: 281

  43. {6, 6, 5}

    Returns: 566

  44. {2, 7, 7}

    Returns: 277

  45. {1, 3, 8}

    Returns: 183

  46. {6, 8, 0, 3, 0}

    Returns: 683

  47. {8, 4, 1, 5}

    Returns: 4581

  48. {0, 5, 6, 9}

    Returns: 569

  49. {7, 6, 9}

    Returns: 769

  50. {1, 1, 6, 3, 7}

    Returns: 11673

  51. {0, 7, 4, 5}

    Returns: 457

  52. {2, 4, 9, 9, 8}

    Returns: 24989

  53. {9, 4, 3}

    Returns: 349

  54. {7, 5, 4, 2, 1}

    Returns: 12457

  55. {6, 7, 4, 7, 4}

    Returns: 46477

  56. {5, 0, 9, 4, 2}

    Returns: 2459

  57. {9, 2, 5}

    Returns: 529

  58. {2, 1, 6}

    Returns: 261

  59. {4, 2, 0, 8, 8}

    Returns: 4882

  60. {7, 6, 0}

    Returns: 67

  61. {8, 5, 9}

    Returns: 859

  62. {5, 7, 2, 2}

    Returns: 5227

  63. {2, 7, 2, 5}

    Returns: 5227

  64. {6, 9, 9, 5, 1}

    Returns: 15699

  65. {7, 4, 7, 9, 7}

    Returns: 47779

  66. {7, 5, 4, 3, 6 }

    Returns: 36457

  67. {1, 2, 4 }

    Returns: 241

  68. {9, 2, 4, 7, 8 }

    Returns: 24789

  69. {7, 5, 4, 3, 9 }

    Returns: 34759

  70. {1, 9, 3, 4, 4 }

    Returns: 13449

  71. {2, 5, 9 }

    Returns: 529

  72. {4, 2, 1 }

    Returns: 241

  73. {7, 3, 9, 3, 9 }

    Returns: 33997

  74. {1, 1, 1, 1, 1 }

    Returns: 11111

  75. {4, 0, 9 }

    Returns: 409

  76. {6, 4 }

    Returns: 46

  77. {1, 6, 9 }

    Returns: 619

  78. {1, 8 }

    Returns: 81

  79. {9, 8, 7, 6, 5 }

    Returns: 56897

  80. {5, 2, 9 }

    Returns: 529

  81. {7, 6, 7, 5, 7 }

    Returns: 65777

  82. {1, 7 }

    Returns: 17

  83. {1, 2, 1 }

    Returns: 211

  84. {1 }

    Returns: 1

  85. {8, 1 }

    Returns: 81

  86. {0, 0, 0, 2, 1 }

    Returns: 21

  87. {0, 0, 0, 1, 7 }

    Returns: 17


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: