蓝桥杯【历届试题】不能买到的数目

#include <bits/stdc++.h>
using namespace std;
bool a[1005*1005];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        if(n>m)swap(n,m);
        memset(a,0,sizeof(a));
        a[0]=1;
        int notshow=0;
        for(int i=n;i<=n*m;i++)
        {
            if(i>=m)
            a[i]=a[i-n]||a[i-m];
            else
                a[i]=a[i-n];
            if(a[i]==0)
                notshow=max(notshow,i);
            //printf("%d:%d\n",i,a[i]);
        }
        cout<<notshow<<endl;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_37252519/article/details/79354469