C++ can not buy the number (mathematics theorem)

Xiao Ming opened a candy store.
He is ingenious: Pack the fruit candy into two packs of 4 and 7 pieces.
Candies cannot be sold unpacked.
When a child comes to buy sweets, he uses these two packages 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 quantity of two packages is known.
Input format
Two positive integers n, m, indicating the number of sugar in each package.
Output format
A positive integer, indicating the maximum amount of sugar that cannot be bought.
The data range is
2≤n, m≤1000 to ensure that the data must be solved.
Input sample:
4 7
Output sample:
17

For this kind of math theorem test, if you don’t know the formula, you can print a lot of results and find the rules.
AC code:

#include<stdio.h>
using namespace std;

int n,m;

int main()
{
    
    
    scanf("%d%d",&n,&m);
    printf("%d",(n-1)(m-1)-1);
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_44643644/article/details/108818483