The 4th Blue Bridge Cup Preliminary-the number that can't be bought

Title description

Xiao Ming opened a candy store. He is ingenious: Pack the fruit candy into two packs of 4 pieces and 7 pieces. Candies cannot be sold unpacked.
When a child comes to buy sweets, he uses these two kinds of packaging to combine. Of course, the number of candies cannot be combined, such as 10 candies.
You can test it with a computer. In this packaging case, the maximum unavailable quantity is 17. Any number greater than 17 can be combined with 4 and 7.
The requirement of this question is to find the largest number that cannot be combined when the quantities of two packages are known.

enter

Two positive integers, indicating the number of sugars in each package (no more than 1000).
Input to ensure that the two positive integers are relatively prime

Output

A positive integer, indicating the maximum amount of sugar that cannot be bought

Sample input

4 7

Sample output

17

code show as below:

#include <iostream>
using namespace std;

int main()
{
    
    
    int p,q;
    cin>>p>>q;
    cout<<p*q-p-q<<endl;
    return 0;
}

Conclusion:
If both a and b are positive integers and relatively prime, then by ax+by, x>=0, y>=0, the largest number that cannot be made up is a*bab

Guess you like

Origin blog.csdn.net/m0_51955470/article/details/113666302