Statistics

Problem Statement for "EllysPrimesMatrix"

Problem Statement

Elly has a matrix of digits. You are given this matrix in the String[] matrix.

Elly calls a prime number hidden in the matrix if it can be created by taking exactly one digit from each row of the matrix and concatenating them (in the order from the first row to the last).

How many distinct prime numbers are hidden in her matrix?

Definition

Class:
EllysPrimesMatrix
Method:
getCount
Parameters:
String[]
Returns:
int
Method signature:
int getCount(String[] matrix)
(be sure your method is public)

Notes

  • A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Please note that the number 1 itself is not a prime.
  • Numbers with leading zeroes are allowed in this problem.

Constraints

  • matrix will contain between 1 and 7 elements, inclusive.
  • Each element of matrix will have length between 1 and 7, inclusive.
  • All elements of matrix will have equal length.
  • Each character in matrix will be a digit ('0'-'9').

Examples

  1. {"5943", "1728", "3451"}

    Returns: 11

    The prime numbers contained in the matrix are: 571, 523, 521, 911, 971, 983, 421, 313, 311, 373, and 383.

  2. {"123", "456", "789", "012", "248"}

    Returns: 0

    Even numbers are very rarely prime. (The only even prime number is 2.)

  3. {"11111", "11111", "11111", "11111", "13579"}

    Returns: 3

    Note that you should find the number of distinct primes that are hidden in the grid. There are only three primes hidden in this grid: 11113, 11117, and 11119. Each of them can be constructed in multiple ways, but we only count each of them once.

  4. {"315509", "712846", "666371", "123456", "789012", "059437", "149573"}

    Returns: 17575

    Some of the primes hidden in the matrix may have leading zeroes. For example, one of the primes in this matrix is 0811777.

  5. {"2"}

    Returns: 1

  6. {"7"}

    Returns: 1

  7. {"9"}

    Returns: 0

  8. {"234567"}

    Returns: 4

  9. {"1", "0", "0", "0", "0", "3", "3"}

    Returns: 1

  10. {"1", "3", "3", "7"}

    Returns: 0

  11. {"42", "21"}

    Returns: 1

  12. {"457", "583"}

    Returns: 3

  13. {"5106", "7672"}

    Returns: 4

  14. {"90973", "70663"}

    Returns: 5

  15. {"612998", "013398"}

    Returns: 8

  16. {"2050961", "2928366"}

    Returns: 8

  17. {"26", "07", "46"}

    Returns: 0

  18. {"756", "826", "221"}

    Returns: 3

  19. {"3147", "9107", "0888"}

    Returns: 0

  20. {"39003", "43099", "44590"}

    Returns: 2

  21. {"456217", "854618", "176898"}

    Returns: 34

  22. {"6247802", "1733715", "4556668"}

    Returns: 0

  23. {"54", "08", "12", "02"}

    Returns: 0

  24. {"030", "961", "558", "588"}

    Returns: 0

  25. {"1953", "3315", "8241", "7383"}

    Returns: 28

  26. {"82407", "70799", "60636", "00873"}

    Returns: 31

  27. {"249261", "115741", "836383", "328812"}

    Returns: 41

  28. {"4681853", "7318860", "2814618", "9262360"}

    Returns: 108

  29. {"28", "83", "00", "19", "54"}

    Returns: 0

  30. {"076", "786", "723", "649", "235"}

    Returns: 22

  31. {"0958", "5433", "0684", "2016", "9832"}

    Returns: 99

  32. {"50821", "08652", "51621", "13737", "37029"}

    Returns: 217

  33. {"811222", "477794", "206564", "275538", "387588"}

    Returns: 117

  34. {"1985880", "1993783", "9133995", "2260324", "7551321"}

    Returns: 350

  35. {"45", "52", "27", "50", "04", "29"}

    Returns: 4

  36. {"438", "298", "827", "265", "104", "003"}

    Returns: 52

  37. {"1192", "5945", "9329", "7639", "2962", "0149"}

    Returns: 113

  38. {"93181", "19489", "14090", "62493", "90644", "79838"}

    Returns: 723

  39. {"039647", "665833", "004120", "259792", "939026", "608952"}

    Returns: 364

  40. {"3121091", "9366292", "3790131", "0351279", "4658010", "4393859"}

    Returns: 1692

  41. {"47", "15", "70", "86", "37", "40", "79"}

    Returns: 22

  42. {"638", "296", "251", "766", "352", "982", "187"}

    Returns: 170

  43. {"1869", "3417", "8502", "5971", "7124", "7412", "8008"}

    Returns: 0

  44. {"37720", "17930", "95235", "77119", "94126", "98212", "41457"}

    Returns: 1640

  45. {"547574", "111465", "501404", "441466", "186271", "692186", "231395"}

    Returns: 1709

  46. {"3751627", "1455829", "6599543", "6726359", "1020356", "6532872", "0410900"}

    Returns: 12768

  47. {"9989002", "6216587", "8229693", "4798788", "6590644", "5692112", "5316040"}

    Returns: 4138

  48. {"8389668", "9933772", "2422491", "7685235", "4671000", "0672608", "7221278"}

    Returns: 3088

  49. {"0521218", "8790802", "5288136", "1010440", "1520685", "2335952", "6100354"}

    Returns: 3746

  50. {"5134720", "0142637", "4270319", "9021368", "8291063", "9628543", "8369417"}

    Returns: 81311

  51. {"2451308", "7430261", "1240786", "7406819", "4097823", "8471039", "9217063"}

    Returns: 80991

  52. {"4215036", "5401823", "1358062", "4028731", "2973105", "7604193", "8479153"}

    Returns: 81477

  53. {"5306421", "2140538", "1482056", "0765314", "9176530", "5067148", "7213489"}

    Returns: 81489

  54. {"2310564", "3018452", "8230461", "5601723", "5631720", "4917852", "8379125"}

    Returns: 81369

  55. {"6450231", "2514063", "0962731", "3042965", "5837690", "3268574", "9621573"}

    Returns: 81412

  56. {"4305261", "0513284", "1326085", "3710546", "0619537", "6273940", "5372691"}

    Returns: 81609

  57. {"5234071", "2601734", "1832705", "8721540", "5742813", "3105479", "7395821"}

    Returns: 81265

  58. {"5463201", "7210438", "4831205", "7124086", "9273081", "6917045", "3529187"}

    Returns: 81241

  59. {"3246150", "4821360", "4201368", "9578403", "5497682", "0326985", "2930178"}

    Returns: 81281

  60. {"6401532", "4305126", "0194528", "9376048", "9187356", "7816593", "1370928"}

    Returns: 81592

  61. {"315509", "712846", "666371", "123456", "789012", "059437", "149573" }

    Returns: 17575

  62. {"0987654", "1234567", "2345678", "3456789", "4567890", "1234567", "1234567" }

    Returns: 58002

  63. {"11111", "11111", "11111", "11111", "13579" }

    Returns: 3

  64. {"00", "00" }

    Returns: 0

  65. {"1357902", "1357902", "1357902", "1357902", "1357902", "1357902", "1357902" }

    Returns: 79926

  66. {"0", "0" }

    Returns: 0

  67. {"5943", "1728", "3451" }

    Returns: 11

  68. {"9000000", "0000000", "0000000", "0000000", "0000000", "1111111", "1111111" }

    Returns: 2

  69. {"00", "22" }

    Returns: 1

  70. {"1234567", "1234567", "1234567", "1234567", "1234567", "1234567", "1234567" }

    Returns: 58314

  71. {"0" }

    Returns: 0

  72. {"9" }

    Returns: 0

  73. {"0000000", "0000000", "0000000", "0000000", "2333333" }

    Returns: 2

  74. {"0", "0", "3" }

    Returns: 1

  75. {"5943432", "1723258", "3422451", "5943432", "5943432", "5943432", "5943432" }

    Returns: 6108


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: