The number of blue bridges cannot be bought.
James opened a candy store. He was ingenious: He made water fructose into four one package and seven one package. Candy cannot be sold in a package.
When a child comes to buy sugar, he uses these two packages for combination. Of course, the quantity of some candy cannot be combined, for example, to buy 10 sugar.
You can test it on a computer. In this case, the maximum number of packages that cannot be purchased is 17. Any number greater than 17 can be combined with 4 and 7.
The requirement for this question is to find the maximum number that cannot be combined when the number of two packages is known.
Input:
Two positive integers, indicating the number of sugar in each package (no more than 1000)
Required output:
A positive integer that indicates the maximum number of sugar that cannot be bought
For example:
User input:
4 7
The program should output:
17
For example:
User input:
3 5
The program should output:
7
Algorithm analysis:
Prove the following two propositions:
1. (x-1) (Y-1)-1 cannot be expressed as the form of ax +
2. equal to or greater than (x-1) (Y-1) can be expressed as an ax + by Form
Proposition 1 can be reversed.
Suppose (x-1) (Y-1)-1 = ax + by (a, B> = 0)
That is, ax + by = xy-x-y
That is, (a + 1) x + (B + 1) y = xy
So a + 1 should be able to divide y, and set a + 1 = cy (c> 0)
Therefore, B + 1 should be able to divide x and Set B + 1 = dx (d> 0)
(C + d) xy = xy
=> C + d = 1
There must be one in c and d <= 0
Conflicts with assumptions
1 #include <iostream>2 using namespace std;3 int main()4 {5 int a, b;6 cin >> a >> b;7 cout << a * b - a - b << endl;8 return 0;9 }