A new change problem
Time Limit: 5000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 533 accepted submission (s): 265
Problem descriptionnow given two kinds of coins a and B, which satisfy that gcd (a, B) = 1. here you can assume that there are enough coins for both kinds. please calculate the maximal value that you cannot pay and the total number that you cannot pay.
Inputthe input will consist of a series of pairs of integers A and B, separated by a space, one pair of integers per line.
Outputfor each pair of input integers A and B you shoshould output the maximal value that you cannot pay and the total number that you cannot pay, and with one line of output for each line in input.
Sample input2 3 3 4
Sample output1 1 5 3
Authorlcy
The recommendlcy question is to give two mutually qualitative numbers A and B. A * x + B * Y (x> = 0, Y> = 0) Ask the maximum number that cannot be expressed, and the number that cannot be expressed. Number theory knowledge; number is (A-1) * (B-1)/2; the maximum cannot represent the number is a * B-A-B; all the number can be divided into Class, the remainder of A is 0 ~ A-1. · For brief derivation, see: http://hi.baidu.com/qq258513813/blog/item/81c1d5c57e9ac7009d163da6.html Code :
# include
int main ()
{< br>
int A, B;
while (scanf (
"
% d
" , & A, & B )! = EOF)
{< br> printf (
"
% d \ n
" , A * B-A-B, (A-
1 ) * (B-
1 )/
2 );
}< br>
return
0 ;< BR >}