The number of blue bridges cannot be bought.

Source: Internet
Author: User

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 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.