1 条题解

  • 0
    @ 2025-9-9 23:46:57

    C++ :

    #include<cstdio>
    #include<algorithm>
    int a,b;
    bool check(long long x)
    {
        for (int idx=x%10; x; x/=10)
            if (x%10!=idx)
                return 0;
        return 1;
    }
    long long solve(long long x)
    {
        while (1)
            if (check(x))
                if (x%5==0)
                    x+=a+b;
                else
                    x+=b;
            else if (x%5==0)
                x+=a;
            else
                break;
        return x;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        for (int cas=1; cas<=t; cas++)
        {
            scanf("%d%d",&a,&b);
            printf("Case #%d: ",cas);
            if (a%10==0 || a%25==0 || a==35)
            {
                puts("INF");
                continue;
            }
            if (a%5==0 && b%5==0)
            {
                puts("INF");
                continue;
            }
            if (a%5==0)
            {
                long long ans=0;
                for (int i=0; i<=10000; i+=5)
                {
                    long long j=5;
                    while (j<i)
                        j=j*10+5;
                    while ((j-i)%a!=0)
                        j=j*10+5;
                    ans=std::max(ans,j+a+b);
                }
                int tmp=9999+b;
                if (tmp%5==0)
                {
                    long long j=5;
                    while (j<tmp)
                        j=j*10+5;
                    while ((j-tmp)%a!=0)
                        j=j*10+5;
                    ans=std::max(ans,j+a+b);
                }
                printf("%lld\n",ans);
                continue;
            }
            long long ans=0;
            for (int i=1; i<=10000; i++)
                ans=std::max(ans,solve(i));
            printf("%lld\n",ans);
        }
        return 0;
    }
    
    
    • 1

    信息

    ID
    1176
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者