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 404instead. 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

那个前导0是真的坑 学到了
 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
#include <cstring>
using namespace std;
string s;
int _deal(int x)
{
if(x<=) return ;
int flag=;
for(int i=;i*i<=x;i++){
if(x%i==){
flag=;
break;
}
}
return flag;
}
int main()
{
int n,m;
while(cin>>n>>m){
cin>>s;
int flag=,sum=,t=;
for(int i=;i<=n-m;i++){
sum=,t=;
for(int j=i+m-;j>=i;j--){
sum+=t*int(s[j]-'');
t*=;
}
if(_deal(sum)){
flag=;
printf("%0*d\n",m,sum);//坑啊
break;
}
}
if(!flag)cout<<""<<endl;
}
return ;
}

PAT (Advanced Level) Practice 1152 Google Recruitment (20 分)的更多相关文章

  1. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  2. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  3. PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...

  4. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

  5. PAT (Advanced Level) Practice 1120 Friend Numbers (20 分) (set)

    Two integers are called "friend numbers" if they share the same sum of their digits, and t ...

  6. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

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

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

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

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

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

随机推荐

  1. 本地linux搭建的WordPress升级时需要输入FTP信息

    转自:https://blog.csdn.net/weixin_43837883/article/details/88751871 这是因为目录权限不正确所致 解决方法: 1.使用命令chown -R ...

  2. 阿里云服务器ECS Ubuntu18.04 初次使用配置教程(图形界面安装)

    最近由于工作需要,要使用服务器测试,就先自已买了个服务器,就在阿里云买了一个,先买了那个叫虚拟主机的,后来发现不是我需要的,所以退了,就先了这个ECS主机.3年.如果购买就上图了.下面直接进入正题. ...

  3. JS代码格式化时间戳

    一.[24小时制]yyyy-MM-dd HH:mm:ss new Date().toJSON() // 2019-12-13T13:12:32.265Z 通过上面的方法,基本就可以将日期格式化,然后稍 ...

  4. VFP中OCX控件注册检测及自动注册

    这是原来从网上搜集.整理后编制用于自己的小程序使用的OCX是否注册及未注册控件的自动注册函数. CheckCtrlFileRegist("ctToolBar.ctToolBarCtrl.4& ...

  5. Chrome开发者工具使用指南

    前言 工欲善其事,必先利其器. 在前端工作中,我们常常使用到Chrome开发者工具去做各种各样的事情. 但是您真的了解这些开发者工具吗? 官方文档还是挺详细的:chrome-devtools文档. 但 ...

  6. Git简易教程(常用命令)

    本文章参考了Pro Git 1 Git简介 Linux内核开源项目有着众多参与者,为了提高开发效率,项目组于2002年开始启用分布式版本控制系统BitKeeper来管理和维护代码.在BitKeeper ...

  7. java如何解决线程安全问题

    方式一:同步代码块 synchroized(同步监视器的对象){需要被同步的代码} package threadtest; //使用同步代码块实现Runable接口的线程 public class R ...

  8. jQuery XSS漏洞

    漏洞成因: jQuery中过滤用户输入数据所使用的正则表达式存在缺陷,可能导致location.hash跨站脚本攻击. 演示程序: <!DOCTYPE html> <html lan ...

  9. python——面向对象基础(2),烤地瓜

    """Date:2020.2.9 测试案例:烤地瓜需求分析1.烤的时间和对应的地瓜状态:2.烤制过程步骤: 1.定义类, 地瓜属性,状态,烤的时间,调料 2.定义方法,怎 ...

  10. pom.xml配置文件详解(Maven)

    注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 注:本文转载自:https://blog.csdn.net/u012152619/article/deta ...