1152 Google Recruitment (20 分)

水~。

int n,k;

bool isprime(int x)
{
    for(int i=2;i*i<=x;i++)
        if(x % i == 0)
            return false;
    return true;
}

int main()
{
    cin>>n>>k;

    string s;
    cin>>s;

    string res="404";
    for(int i=0;i<n;i++)
    {
        string t=s.substr(i,k);
        if(t.size() < k) break;
        if(isprime(stoi(t)))
        {
            res=t;
            break;
        }
    }

    cout<<res<<endl;
    //system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/fxh0707/p/14485039.html