题干前半略。

Input Specification:

Each input file contains one test case. Each case first gives in a line two positive integers: L (≤ 1,000) and K (< 10), which are the numbers of digits of the given number and the prime to be found, respectively. Then the L-digit number N is given in the next line.

Output Specification:

For each test case, print in a line the first K-digit prime in consecutive digits of N. If such a number does not exist, output 404 instead. Note: the leading zeroes must also be counted as part of the K digits. For example, to find the 4-digit prime in 200236, 0023 is a solution. However the first digit 2 must not be treated as a solution 0002 since the leading zeroes are not in the original number.

Sample Input 1:

20 5
23654987725541023819
 

Sample Output 1:

49877
 

Sample Input 2:

10 3
2468024680
 

Sample Output 2:

404

#include<stdio.h>
#include<vector>
#include<string>
#include<iostream>
#include<math.h>
using namespace std; bool isprime(int n)
{ if(n==1||n==0) return false;
for(int i=2;i<=(int)sqrt(n);i++)
{
if(n%i==0) return false;
}
return true;
}
bool flag;
int main()
{
int num;
int primenum;
scanf("%d",&num);
scanf("%d",&primenum);
string seq;
cin>>seq;
while(seq[0]=='0') seq.erase(seq.begin());
int i;
for(i=0;i<num;i++)
{
int start=i;
char temp[20];
int t=0;
if(num-i<primenum) break;
for(int j=i;j<i+primenum;j++)
{
temp[t++]=seq[j];
}
int newnum;
sscanf(temp,"%d",&newnum);
temp[t]='\0';
if(isprime(newnum))
{
cout<<temp;
flag=true;
return 0;
}
}
if(i==num-primenum+1) printf("404\n");
}

1152 Google Recruitment的更多相关文章

  1. PAT 1152 Google Recruitment

    1152 Google Recruitment (20 分)   In July 2004, Google posted on a giant billboard along Highway 101 ...

  2. PAT甲级——1152.Google Recruitment (20分)

    1152 Google Recruitment (20分) In July 2004, Google posted on a giant billboard along Highway 101 in ...

  3. PAT甲级:1152 Google Recruitment (20分)

    PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...

  4. pat甲级 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  5. 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  6. PAT Advanced 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  7. PAT (Advanced Level) Practice 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  8. PAT_A1152#Google Recruitment

    Source: PAT A1152 Google Recruitment (20 分) Description: In July 2004, Google posted on a giant bill ...

  9. PAT-1152(Google Recruitment)字符串+素数

    Google Recruitment PAT-1152 本题最需要注意的是最后输出要以字符串形式输出,否则可能会出现前导0的情况. /** * @Author WaleGarrett * @Date ...

随机推荐

  1. MATLAB在读取excel文件是发生错误,怎么解决?

    转载:https://blog.csdn.net/qq_38712026/article/details/78783422?utm_source=blogxgwz4

  2. python安装whl包时出现的问题解决:is not a supported wheel on this platform

    @ 目录 一.问题 二.查找问题 三.问题解决 一.问题 1.下载一个twisted包 安装Twisted,进入https://www.lfd.uci.edu/~gohlke/pythonlibs 下 ...

  3. 实现一个简单的 Linux Shell(C++)

    Implement a simple command interpreter in Linux. The interpreter should: support both internal and e ...

  4. Java设计模式精讲之UML急速入门

    简单记录 - 慕课网 - Java设计模式精讲 Debug方式+内存分析 文章目录 第2章 UML急速入门 2-1.UML简单入门 UML定义 UML特点 UML 2.2分类 UML类图 理解泛化.实 ...

  5. 创建mysql帐户

    CREATE USER 'username'@'host' IDENTIFIED BY 'password';

  6. [翻译]Azure 网关迁移至 .NET Core 3.1 性能提升一倍

    原文:[Azure Active Directory's gateway is on .NET Core 3.1!] Azure Active Directory 的网关服务是一个反向代理,它为构成 ...

  7. C# 关机/重启/注销计算机

    一.调用 shutdown.exe 执行操作 调用 shutdown.exe 执行计算机关机.重启.注销操作,还可以设置多长时间后执行操作,代码如下: 1 /// <summary> 2 ...

  8. 入门OJ:Coin

    题目描述 你有n个硬币,第i硬币面值为ai,现在总队长想知道如果丢掉了某个硬币,剩下的硬币能组成多少种价值?(0价值不算) 输入格式 第一行一个整数n 第二行n个整数.,a1,a2-an. 1< ...

  9. CUDA 介绍

    1. 介绍 1.1 GPU vs. CPU GPU 使用更多的晶体管进行数据处理,而不是数据缓存和流控制,因此可以提供高度的并行计算. GPU 可以通过计算来隐藏内存访问延迟,而不是依赖于大量的数据缓 ...

  10. 使用Bat自动打包并通过FTP发送到备份服务器——实战测试

    这个bat文件要求本地安装有winrar解压软件,位置是:C:\Program Files\WinRAR\WinRAR.exe 如果执行报错,请检查你复制我的代码是否有问题,有些复制粘贴进去后因为一些 ...