1152 Google Recruitment (20 分)【难度: 简单 / 知识点: 模拟】

在这里插入图片描述
https://pintia.cn/problem-sets/994805342720868352/problems/1071785055080476672

#include<bits/stdc++.h>
using namespace std;
int n,k; 
string s;
bool check(string s)
{
    
    
	long long int a=stol(s);
    if(a<=1) return false; //会卡测试点2
	for(long long int i=2;i<=a/i;i++) if(a%i==0) return false;
    cout<<s;
	return true;
}
int main(void)
{
    
    
	cin>>n>>k;
	cin>>s;
	for(int i=0;i<=n-k;i++)
	{
    
    
		string temp=s.substr(i,k);
		if(check(temp)) return 0;
	}
	cout<<"404"; 
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_46527915/article/details/121581411