1152 Google Recruitment (20 分)
 

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<bits/stdc++.h>
using namespace std;
typedef long long ll; ll to_int(string s){
ll sum = ;
for(int i=;i < s.size();i++){
sum = sum*+(s[i]-'');
}
return sum;
} bool is_prime(ll x){
for(int i=;i <= sqrt(x);i++){
if(x%i == ) return false;
}
return true;
} int main(){
int len,n;
cin >> len >> n;
string s;
cin >> s; int flag = ;
for(int i=;i <= len-n;i++){
string temp = s.substr(i,n);
ll num = to_int(temp);
if(is_prime(num)){
cout << temp;
flag = ;
break;
}
} if(flag) cout << ; return ;
}

_一开始想复杂了以为要筛一下,其实直接判断素数就可以了,因为长度限制在1000以内,1000*10^5  = 10^8不会爆掉

噢对了,用stastic int可以申请到更大的空间数组(静态空间大小),用malloc申请到的更大(磁盘区大小),普通的数组是在栈空间申请,比较小。

PAT 1152 Google Recruitment的更多相关文章

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

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

  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 分)

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

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

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

  6. 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. PAT-1152(Google Recruitment)字符串+素数

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

随机推荐

  1. 使用Spring的@Async创建异步方法

    使用Spring的@Async创建异步方法 在开发系统的过程中,通常会考虑到系统的性能问题,提升系统性能的一个重要思想就是“串行”改“并行”.说起“并行”自然离不开“异步”,今天我们就来聊聊如何使用S ...

  2. 微信不支持App下载的解决方案 微信跳转打开外部浏览器下载(苹果跳转商店下载)

    在微信中,打开app下载链接,或者使用微信扫一扫app下载二维码,都是无法下载app的. 因为腾讯为了自身利益,屏蔽了其他app直接在微信中下载.下面给分享下,找到的2种有效的解决方案. 方案:点击链 ...

  3. 认识.net

    .NET多指NET Framework,Visual Studio.NET及其开发的应用程序.NET Framework是一个开发和执行环境,允许不同的程序语言和库无缝结合基于Window的应用程序. ...

  4. 用AOP记录操作日志,并写进数据库。

    先用AOP注解 1 package com.vlandc.oss.apigate.log.aspect; import java.util.Map; import java.util.Optional ...

  5. Exp1 PC平台逆向破解 20164303 景圣

    逆向及Bof基础实验 实验对象 文件名为pwn1的linux可执行文件. 实验目标:程序正常执行流程weimain调用foo函数,foo函数会简单回显任何用户输入的字符串.该程序同时包含另一个代码片段 ...

  6. JSESSIONID的简单说明

    原文地址:http://blog.csdn.net/chunqiuwei/article/details/23461995 1)第一次访问服务器的时候,会在响应头里面看到Set-Cookie信息(只有 ...

  7. Servlet和Filter的区别

    1.Filter是一个接口,而Servlet是一个类继承于Httpservlet 2.生命周期的不同,Filter在Web App被加载时,创建该Filter的实例,并调用init()方法(仅创建一个 ...

  8. go 笔记

    Go 语言的变量声明格式为: var 变量名 变量类型 返回类型. 匿名变量不占用命名空间,不会分配内存.匿名变量与匿名变量之间也不会因为多次声明而无法使用. func GetData() (int, ...

  9. idea工具和激活码获取

    1.下载最新的idea https://blog.csdn.net/mashuai720/article/details/79389314 2.获取激活码 最后一个有效,亲测 https://blog ...

  10. linux中查找(find、locate、which、whereis、grep)命令汇总、帮助命令(man、whatis、apropos、info、help)汇总

    (一)find命令详解 find:功能:文件搜索: 语法:find[搜索范围][匹配条件]:  只要匹配条件完全符合才可以被显示,使用通配符*匹配条件*则可以显示匹配条件的所有目录,问号?匹配单个字符 ...