NOIP 2017 小凯的疑惑

引用博主:Hany01的文章 NOIP 2017 小凯的疑惑 (数学)

博文地址:https://blog.csdn.net/hhaannyyii/article/details/78618358


分析:

(野路子:因为>=a*b的数都能由a和b组成,这个可以证明(此处省略)。那么就考虑小于a*b的数。简单想法就是找几对小的a和b,把最大不能组成的数推出,再尝试写出公式。(考试时学生是这么想的:3和7,答案11,不就是3×7-3-7=11,再找几组数据测试,完美100分)

不妨设a<b,假设答案为x,

若x≡ma(modb)(1≤m≤b−1) 

即x=ma+nb(1≤m≤b−1)

显然当 n≥0时 x可以用 a,b表示出来,不合题意。

因此当n=−1 时 x 取得最大值,此时 x=ma−b 。

显然当m取得最大值 b−1时x 最大,此时x=(b−1)a−b=ab−a−b

因此a,b所表示不出的最大的数是ab−a−b


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define LL long long
using namespace std;
inline LL read() {
    LL d=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
    return d*f;
}
long long l;
int main()
{
    int a=read(),b=read();
    l=(long long)a*b-a-b;
    cout<<l;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/blaze003003/article/details/81094088