PAT 1152 Google Recruitment
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的更多相关文章
- PAT甲级:1152 Google Recruitment (20分)
PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...
- PAT甲级——1152.Google Recruitment (20分)
1152 Google Recruitment (20分) In July 2004, Google posted on a giant billboard along Highway 101 in ...
- pat甲级 1152 Google Recruitment (20 分)
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...
- 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 ...
- 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 ...
- 1152 Google Recruitment (20 分)
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...
- 1152 Google Recruitment
题干前半略. Input Specification: Each input file contains one test case. Each case first gives in a line ...
- PAT_A1152#Google Recruitment
Source: PAT A1152 Google Recruitment (20 分) Description: In July 2004, Google posted on a giant bill ...
- PAT-1152(Google Recruitment)字符串+素数
Google Recruitment PAT-1152 本题最需要注意的是最后输出要以字符串形式输出,否则可能会出现前导0的情况. /** * @Author WaleGarrett * @Date ...
随机推荐
- phpStudy环境安装SSL证书教程
第一步:修改apache目录下的httpd.conf配置文件(D:\phpStudy\PHPTutorial\Apache\conf\ ) #LoadModule ssl_module modules ...
- QT 添加外部库文件
LIBS += D:\Code\Opengltest\OpenGL32.Lib D:\Code\Opengltest\GlU32.Lib LIBS += OpenGL32.Lib GlU32.Lib ...
- Java序列化,解决字段为null与序列化后首字母变小写问题
fastjson.jar package com.apt.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.se ...
- FL studio里的项目设置介绍
FL studio作为具有众多音乐功能,能够制作多轨音频录制,排序和混音的一款专业软件,我们可以借助VST主机,灵活的调音台,高级MIDI和ReWire支持,来创建专业品质的各种音乐曲目. 而今天我们 ...
- netty初试
netty官网:点击进入 学习netty之实现一个丢弃服务器 环境: JDK1.8 netty5.0+ 步骤: 实现一个丢弃服务器 实现一个客户端发送数据 丢弃服务器的创建 //用于接受客户端的的连接 ...
- eclipse中出现An internal error occurred during: "Initializing Java Tooling"
关于这个问题我查了一下,就是删除.projct文件夹下的文件. 自己试了一下,这个可以及解决问题可是会出现新的问题. 1.SVN关联没了,这样做你的svn信息都没了,项目还要重新导一遍 2.出现了新的 ...
- windows中cmd常用命令收集
1.经常会启动端口后忘关,需要杀端口的命令:查找端口占用命令 netstat -ano|findstr 端口例如 (8081) 杀端口: taskkill /pid xxxxx - ...
- jQuery (含义 及 优缺点)
jQuery是一套开源的JavaScript函数库,它主要是简化了对DOM的操作.兼容CSS3,兼容各大主流浏览器. 二.jQuery的特点: 1:轻量级的JS函数库 jQuery的核心js文件几十K ...
- 防cc攻击策略
黑客攻击你的网站,会采取各种各样的手段,其中为了降低你网站的访问速度,甚至让你的服务器瘫痪,它会不断的刷新你的网站,或者模拟很多用户同一时间大量的访问你的网站, 这就是所谓的CC攻击,这就需要我们在程 ...
- golang协程踩坑记录
1.主线程等待多个协程执行完毕后,再执行下面的程序.golang提供了一个很好用的工具. sync.WaitGroup下面是个简单的例子. 执行结果: 2.主线程主动去结束已经启动了的多个协程.执行结 ...