入门赛E题求调
  • 板块灌水区
  • 楼主Nephren
  • 当前回复21
  • 已保存回复22
  • 发布时间2024/10/18 21:13
  • 上次更新2024/10/18 23:11:38
查看原帖
入门赛E题求调
1436750
Nephren楼主2024/10/18 21:13
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,ans=0;
int main()
{
    cin>>a>>b>>c>>d;
    if(a==b)
    {
        if(c==0)
        {
            int ok=1;
            for(int j=2;j*j<=b;j++)
            {
                if(b%j==0)
                {
                    ok=0;
                    break;
                }
            }
            if(ok==1)cout<<b;
            else cout<<-1;
        }
        else if(c>=1&&c<=b)
        {
            int ok=1;
            for(int j=2;j*j<=c;j++)
            {
                if(c%j==0)
                {
                    ok=0;
                    break;
                }
            }
            if(ok==1)cout<<c;
            else cout<<-1;
        }
        else cout<<-1;
        return 0;
    }
    for(int i=(a-c)/b;i>=0;i--)
    {
        int ok=1;
        for(int j=2;j*j<=i*b+c;j++)
        {
            if((i*b+c)%j==0)
            {
                ok=0;
                break;
            }
        }
        if(ok==0)continue;
        else ans++;
        if(ans==d){cout<<i*b+c;return 0;}
    }
    cout<<-1;
}

气死我了要是过了第一个点就AK入门赛了,求各路大佬帮我看看问题出在哪谢谢

2024/10/18 21:13
加载中...