Roll the Dice
Time limit1sMemory limit128 MB
Count ordered pairs (a, b) with a from 1 to m, b from 1 to n, and a + b = 10, then print the count with singular or plural wording.
- Level
Easy1 of 10
- Topics
- Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
Diana is playing a game with two dice. The first die has faces labelled . The second die has faces labelled . Write a program that determines how many ways she can roll the two dice so that the two faces add up to .
Each way is an ordered pair made of one face value from the first die and one face value from the second die whose sum is exactly . Two ways are considered different if either die shows a different value.
Input
The input consists of two integers, each on its own line. The first line contains (), the number of faces on the first die. The second line contains (), the number of faces on the second die.
Output
Print the number of ways to roll a sum of on the two dice. Use the singular word "way" when there is exactly one way and the plural word "ways" otherwise. For example, when there is exactly one way, print:
There is 1 way to get the sum 10.
Otherwise, print in the following form (with the count filled in):
There are 5 ways to get the sum 10.