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. vuex 入坑篇

    Vuex 是什么? Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 这个状态自管理应用包含 ...

  2. 如何在linux上查看tomcat的端口号

    1.先到tomcat配置文件查看tomcat的端口是什么,配置文件一般是:$CATALINA_HOME/conf/server这个文件,查找<Connector port="8080& ...

  3. 【.NET】 HTTP协议之webrequest

    零——简介 一.GET 二.POST emmm在post这里在了很多跟头,记忆很深刻. 2.1 传json的Post:简单粗暴的两个参数 一个是网址(接口),一个是json数据 分为了六个步骤  : ...

  4. Linux笔记 #10# 用于支持Web应用开发&部署&配置的一些自定义脚本

    索引 一.本地开发与测试相关脚本 1.startup.sh 2.shutdown.sh 3.catalina-out.sh 4.localhost_access_log.sh 5.上传本地文件到服务器 ...

  5. 【题解】Luogu P4381 [IOI2008]Island

    原题传送门 题意:求基环树森林的直径(所有基环树直径之和) 首先,我们要对环上所有点的子树求出它们的直径和最大深度.然后,我们只用考虑在环上至少经过一条边的路径.那么,这种路径在环上一定有起始点和终点 ...

  6. ORA-28002密码失效问题解决

    问题:提示ORA-28002解决: 第1种方法:数据库级别,需要重启查看过期时间: sql>SELECT * FROM dba_profiles WHERE profile='DEFAULT' ...

  7. 图像旋转、伸缩的自写matlab实现

    一.图像的旋转 今天的代码不是自己写的,缺少一些时间.但是认认真真推导了一下旋转的公式,代码的思想与原博博主一致,致敬! 愚以为,自己来实现图像旋转算法的关键点有二:其一,确定旋转后的图像边界.其二, ...

  8. git checkout --ours 【学习笔记】

    用新分支:git checkout --theirs 文件用master分支:git checkout --ours 文件 执行之后git add

  9. 【做题】SRM701 Div1 Hard - FibonacciStringSum——数学和式&矩阵快速幂

    原文链接 https://www.cnblogs.com/cly-none/p/SRM701Div1C.html 题意:定义"Fibonacci string"为没有连续1的01串 ...

  10. Spark机器学习基础二

    无监督学习 0.K-means from __future__ import print_function from pyspark.ml.clustering import KMeans #from ...