TwoCardsDraw
Rookie SRM 17 · 2022-09-22 · by erinn
Problem Statement
You have several cards, each with a number printed on them, given in
What is the probability that the value is prime?
Notes
- No leading zeroes are added when concatenating the numbers.
Constraints
- cards will contain between 1 and 50 elements, inclusive.
- Each element of cards will be between 1 and 99, inclusive.
{ 1 }
Returns: 1.0
The only number you're going to get after concatenation is 11, so it's definitely prime.
{ 1, 3 }
Returns: 0.75
11, 13, and 31 are prime, but 33 is not.
{ 2, 4 }
Returns: 0.0
No number you get will be prime.
{ 11, 12, 13 }
Returns: 0.1111111111111111
{ 1, 1, 3 }
Returns: 0.8888888888888888
Notice that numbers can be repeated.
Submissions are judged against all 8 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TwoCardsDraw with a public method double primeChance(vector<int> cards) · 8 test cases · 2 s / 256 MB per case