Problem Statement
Elly has a matrix of digits. You are given this matrix in the
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
{"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.
{"123", "456", "789", "012", "248"}
Returns: 0
Even numbers are very rarely prime. (The only even prime number is 2.)
{"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.
{"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.
{"2"}
Returns: 1
{"7"}
Returns: 1
{"9"}
Returns: 0
{"234567"}
Returns: 4
{"1", "0", "0", "0", "0", "3", "3"}
Returns: 1
{"1", "3", "3", "7"}
Returns: 0
{"42", "21"}
Returns: 1
{"457", "583"}
Returns: 3
{"5106", "7672"}
Returns: 4
{"90973", "70663"}
Returns: 5
{"612998", "013398"}
Returns: 8
{"2050961", "2928366"}
Returns: 8
{"26", "07", "46"}
Returns: 0
{"756", "826", "221"}
Returns: 3
{"3147", "9107", "0888"}
Returns: 0
{"39003", "43099", "44590"}
Returns: 2
{"456217", "854618", "176898"}
Returns: 34
{"6247802", "1733715", "4556668"}
Returns: 0
{"54", "08", "12", "02"}
Returns: 0
{"030", "961", "558", "588"}
Returns: 0
{"1953", "3315", "8241", "7383"}
Returns: 28
{"82407", "70799", "60636", "00873"}
Returns: 31
{"249261", "115741", "836383", "328812"}
Returns: 41
{"4681853", "7318860", "2814618", "9262360"}
Returns: 108
{"28", "83", "00", "19", "54"}
Returns: 0
{"076", "786", "723", "649", "235"}
Returns: 22
{"0958", "5433", "0684", "2016", "9832"}
Returns: 99
{"50821", "08652", "51621", "13737", "37029"}
Returns: 217
{"811222", "477794", "206564", "275538", "387588"}
Returns: 117
{"1985880", "1993783", "9133995", "2260324", "7551321"}
Returns: 350
{"45", "52", "27", "50", "04", "29"}
Returns: 4
{"438", "298", "827", "265", "104", "003"}
Returns: 52
{"1192", "5945", "9329", "7639", "2962", "0149"}
Returns: 113
{"93181", "19489", "14090", "62493", "90644", "79838"}
Returns: 723
{"039647", "665833", "004120", "259792", "939026", "608952"}
Returns: 364
{"3121091", "9366292", "3790131", "0351279", "4658010", "4393859"}
Returns: 1692
{"47", "15", "70", "86", "37", "40", "79"}
Returns: 22
{"638", "296", "251", "766", "352", "982", "187"}
Returns: 170
{"1869", "3417", "8502", "5971", "7124", "7412", "8008"}
Returns: 0
{"37720", "17930", "95235", "77119", "94126", "98212", "41457"}
Returns: 1640
{"547574", "111465", "501404", "441466", "186271", "692186", "231395"}
Returns: 1709
{"3751627", "1455829", "6599543", "6726359", "1020356", "6532872", "0410900"}
Returns: 12768
{"9989002", "6216587", "8229693", "4798788", "6590644", "5692112", "5316040"}
Returns: 4138
{"8389668", "9933772", "2422491", "7685235", "4671000", "0672608", "7221278"}
Returns: 3088
{"0521218", "8790802", "5288136", "1010440", "1520685", "2335952", "6100354"}
Returns: 3746
{"5134720", "0142637", "4270319", "9021368", "8291063", "9628543", "8369417"}
Returns: 81311
{"2451308", "7430261", "1240786", "7406819", "4097823", "8471039", "9217063"}
Returns: 80991
{"4215036", "5401823", "1358062", "4028731", "2973105", "7604193", "8479153"}
Returns: 81477
{"5306421", "2140538", "1482056", "0765314", "9176530", "5067148", "7213489"}
Returns: 81489
{"2310564", "3018452", "8230461", "5601723", "5631720", "4917852", "8379125"}
Returns: 81369
{"6450231", "2514063", "0962731", "3042965", "5837690", "3268574", "9621573"}
Returns: 81412
{"4305261", "0513284", "1326085", "3710546", "0619537", "6273940", "5372691"}
Returns: 81609
{"5234071", "2601734", "1832705", "8721540", "5742813", "3105479", "7395821"}
Returns: 81265
{"5463201", "7210438", "4831205", "7124086", "9273081", "6917045", "3529187"}
Returns: 81241
{"3246150", "4821360", "4201368", "9578403", "5497682", "0326985", "2930178"}
Returns: 81281
{"6401532", "4305126", "0194528", "9376048", "9187356", "7816593", "1370928"}
Returns: 81592
{"315509", "712846", "666371", "123456", "789012", "059437", "149573" }
Returns: 17575
{"0987654", "1234567", "2345678", "3456789", "4567890", "1234567", "1234567" }
Returns: 58002
{"11111", "11111", "11111", "11111", "13579" }
Returns: 3
{"00", "00" }
Returns: 0
{"1357902", "1357902", "1357902", "1357902", "1357902", "1357902", "1357902" }
Returns: 79926
{"0", "0" }
Returns: 0
{"5943", "1728", "3451" }
Returns: 11
{"9000000", "0000000", "0000000", "0000000", "0000000", "1111111", "1111111" }
Returns: 2
{"00", "22" }
Returns: 1
{"1234567", "1234567", "1234567", "1234567", "1234567", "1234567", "1234567" }
Returns: 58314
{"0" }
Returns: 0
{"9" }
Returns: 0
{"0000000", "0000000", "0000000", "0000000", "2333333" }
Returns: 2
{"0", "0", "3" }
Returns: 1
{"5943432", "1723258", "3422451", "5943432", "5943432", "5943432", "5943432" }
Returns: 6108