Codeforces 9A Die Roll Solution & Explanation

Difficulty : 800

Problem Description

Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.

But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That’s why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.

Yakko thrown a die and got Y points, Wakko — W points. It was Dot’s turn. But she didn’t hurry. Dot wanted to know for sure what were her chances to visit Transylvania.

It is known that Yakko and Wakko are true gentlemen, that’s why if they have the same amount of points with Dot, they will let Dot win.

Input

The only line of the input file contains two natural numbers Y and W — the results of Yakko’s and Wakko’s die rolls.

Output

Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».

Examples

Input4 2
Output1/2

Note

Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.


Solution

We have two solutions to solve this problem.

The first one involves using a switch case to define all possible answers. The other solution is to dynamically calculate the probabilities.

C# Solution

Solution1

int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int max = Math.Max(arr[0],arr[1]);

string res = "";
switch(max){
    case 1: 
        res = "1/1";
        break;
    case 2: 
        res = "5/6";
        break;
    case 3: 
        res = "2/3";
        break;
    case 4: 
        res = "1/2";
        break;
    case 5: 
        res = "1/3";
        break;
    case 6: 
        res = "1/6";
        break;
}

Console.WriteLine(res);

Solution2

int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int max = Math.Max(arr[0],arr[1]);

int cnt = 6-max+1; //win when the points equal

int gcd = GCD(cnt, 6);
int num = cnt/gcd;  //Numerator
int den = 6 / gcd;  //Denominator

string res = $"{num}/{den}";
Console.WriteLine(res);

int GCD(int a, int b) {
    while (b != 0) {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

In the second solution, we use *GCD(Greatest common divisor) to calculate the answer.

This approach ensures that the resulting answer is presented in its simplest fraction form.

Klook.com

Conclusion

Reference

🧡 It would be my pleasure if my solution proves helpful to you!

🧡 If you find my posts valuable, I would greatly appreciate your support through sharing. Thank you in advance!

✅ If you encounter any issues with the explanation or require solutions in other programming languages, please don’t hesitate to reach out to me!

The problem link : Problem – 9A – Codeforces

Some Random Codeforces Posts

Leave a Reply

Your email address will not be published. Required fields are marked *