[17NOIP Improvement Team] T2 Xiaokai’s doubts

P3951 Xiaokai's doubts

Topic portal

Idea:
If a<b,
suppose x is the answer:
x = ma + nbx=ma+nbx=m a+n b
Obviously, n>=0, x will definitely be expressed, which does not meet the meaning of
thequestion. Then suppose n=-1, then x=ma-b is
the largest that cannot be expressed. So, is it enough to make m the largest?
Let's discuss it in three situations:

  1. m=b, bring it into the original formula:
    x = ma − bx=ma-bx=m ab
    得 : x = b a − b 得:x=ba-b Get : x=b ab
    means x = (a − 1) b means x=(a-1)bI.e. x=(a1 ) b
    then n is not greater than 0, which does not meet the meaning of the question

  2. m>b, suppose m=b+1;
    bring back to the original formula: (b+1)ab
    ad+ab
    (a-1)b+a
    bring back ma+nb, you will find that n=a-1, then this It's not a positive number anymore, it doesn't meet the meaning of the question.

  3. m<b, then the maximum is b-1
    brought back to the original formula: (b-1)ab
    and then you will find that this is not enough.
    So simplify again:
    Answer: ab-ab

#include<bits/stdc++.h>
long long a,b;
int main()
{
    
    
    scanf("%lld%lld",&a,&b);
    printf("%lld\n",(a*b-a-b);
    return 0;
}

Guess you like

Origin blog.csdn.net/bigwinner888/article/details/108139944