## CCC '06 J2 - Roll the Dice

View as PDF

Points: 3
Time limit: 2.0s
Memory limit: 64M

Problem type

Diana is playing a game with two dice. One die has sides labelled .

The other die has sides labelled .

Write a program to determine how many ways can she roll the dice to get the sum .

For example, when the first die has 6 sides and the second die has 8 sides, there are 5 ways to get the sum :

• 2 + 8 = 10
• 3 + 7 = 10
• 4 + 6 = 10
• 5 + 5 = 10
• 6 + 4 = 10

#### Input

The input is given as two integers. First, the user will enter in the number  .

Second, the user will enter the number  .

#### Output

The program prints out the number of ways may be rolled on these two dice. Note that in the output, the word "way" should be used if there is only one way to achieve the sum of ; otherwise, the word "ways" should be used in the output. That is, if there is only one way to get the sum , the output should be:

There is 1 way to get the sum 10.

#### Sample Input 1

6
8

#### Sample Output 1

There are 5 ways to get the sum 10.

#### Sample Input 2

12
4

#### Sample Output 2

There are 4 ways to get the sum 10.

CCC problem statements in large part from the PEG OJ

• Jacob_Tian  commented on Oct. 14, 2018, 8:45 p.m.

i know i messed up so much because of the grammar. :(

• Arihan10  commented on Jan. 22, 2019, 1:55 p.m. edited

Me too :(

Couldn't figure out why I was getting WA.

• ArtyKing12  commented on July 4, 2018, 12:02 p.m.

Did you know that 8!/2/10 = 2016? Figured that out while making an equation for the program

• TimothyW553  commented on Dec. 22, 2017, 6:24 p.m.

Heck the grammar >:(