In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below) for recruitment. The content is super-simple, a URL consisting of the first 10-digit prime found in consecutive digits of the natural constant e. The person who could find this prime number could go to the next step in Google's hiring process by visiting this website.

The natural constant e is a well known transcendental number(超越数). The first several digits are: e = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003059921... where the 10 digits in bold are the answer to Google's question.

Now you are asked to solve a more general problem: find the first K-digit prime in consecutive digits of any given L-digit number.

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<iostream>
#include<algorithm>
using namespace std; bool isPrime(int x){
if(x <= ) return false;
for(int i = ; i*i <= x; i++){
if(x % i == ) return false;
}
return true;
} int main(){
int l,k;
cin >> l >> k;
string s;
cin >> s;
for(int i = ; i < l - k + ; i++){
string str = s.substr(i,k);
int temp = stoi(str);
if(isPrime(temp)){
cout << str;
return ;
}
}
cout << "";
return ;
}

1152 Google Recruitment (20 分)的更多相关文章

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

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

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

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

  3. 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 ...

  4. 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 ...

  5. PAT 1152 Google Recruitment

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

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

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

  7. 1152 Google Recruitment

    题干前半略. Input Specification: Each input file contains one test case. Each case first gives in a line ...

  8. PAT_A1152#Google Recruitment

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

  9. 抛弃EF,20分构建一个属于自己的ORM框架

    Poiuyt_cyc 博客园首页新随笔联系订阅管理随笔 - 11  文章 - 0  评论 - 111 抛弃EF,20分构建一个属于自己的ORM框架 相信EF大家都不陌生了,因为数据库表跟程序实体是一一 ...

随机推荐

  1. intval()函数

    获取变量的整数值 1.转换前转化后 原因:

  2. eclipse——执行Maven命令

    右键pom.xml文件 点击 m2 Maven build... 输入要执行的命令,点击Run 控制台会打印maven运行过程

  3. Win7怎么进入安全模式 三种轻松进入Win7安全模式方法

    发布时间:2013-05-27 11:23 作者:电脑百事网原创 来源:www.pc841.com 13783次阅读 win7的安全模式和XP如出一辙,在安全模式里我们可以删除顽固文件.查杀病毒.解除 ...

  4. ssh试卷

    2.简述Hibernate的工作原理. 答:首先,Configuration读取Hibernate的配置文件及映射文件中的信息,即加载配置文件和映射文件,并通过Hibernate配置文件生成一个多线程 ...

  5. Python基础入门-列表解析式

    今天我们使用Python中的列表解析式来实现一些简单功能.好了关于列表解析式是什么?我的理解是它可以根据已有列表,高效创建新列表的方式.列表解析是Python迭代机制的一种应用,它常用于实现创建新的列 ...

  6. wp8扩展器大全

    <Extensions> <!--扩展照片中心--> <Extension ExtensionName="Photos_Extra_Hub" Cons ...

  7. XXX培训机构Python自动化教程目录

  8. sublime 快捷键 1到9的顺序

    p{$$}*9

  9. 《Effective Java》——读后总结

    这本书在Java开发的行业里,颇有名气.今天总算是粗略的看完了…后面线程部分和序列化部分由于心浮气躁看的不仔细.这个月还剩下一周,慢慢总结消化. 1.静态工厂方法代替构造器 静态工厂方法有名称,能确切 ...

  10. python函数作用域,闭包,装饰器

    第一:函数作用域: L:local 函数内部作用域 E:enclosing       函数内部与内嵌函数之间(闭包) G:global            全局作用域 B:build_in    ...