Connection Status:
Competition Arena > TwoCardsDraw
Rookie SRM 17 · 2022-09-22 · by erinn · Math
Class Name: TwoCardsDraw
Return Type: double
Method Name: primeChance
Arg Types: (vector<int>)
Problem Statement

Problem Statement

You have several cards, each with a number printed on them, given in int[] cards. You select two cards--with replacement--from the deck. You then concatenate the values together to form a single value. For example, if you first selected 5 and then 13, your concatenated value would be 513.

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.
Examples
0)
{ 1 }
Returns: 1.0

The only number you're going to get after concatenation is 11, so it's definitely prime.

1)
{ 1, 3 }
Returns: 0.75

11, 13, and 31 are prime, but 33 is not.

2)
{ 2, 4 }
Returns: 0.0

No number you get will be prime.

3)
{ 11, 12, 13 }
Returns: 0.1111111111111111
4)
{ 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.

Coding Area

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

Submitting as anonymous