PAT_A1152#Google Recruitment
Source:
Description:
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
Keys:
- 素数
Attention:
- int < 1e9, long long <1e18
- 注意主串长度<子串长度的情况
- s.size()返回unsigned类型,l<k时,会死循环
Code:
/*
Data: 2019-08-02 16:31:26
Problem: PAT_A1152#Google Recruitment
AC: 25:40 题目大意:
给定L位数字中找出K位的素数,前导零同样占位
*/
#include<cstdio>
#include<string>
#include<iostream>
using namespace std; bool IsPrime(string s)
{
long long n = atoll(s.c_str());
if(n== || n==)
return false;
for(int i=; i*i<=n; i++)
if(n%i == )
return false;
return true;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE string s;
int l,k;
scanf("%d%d", &l,&k);
cin >> s;
for(int i=; i<=int(s.size())-k; i++)
{
if(IsPrime(s.substr(i,k)))
{
cout << s.substr(i,k).c_str();
s.clear();
break;
}
}
if(s.size() || l<k)
printf(""); return ;
}
PAT_A1152#Google Recruitment的更多相关文章
- PAT 1152 Google Recruitment
1152 Google Recruitment (20 分) In July 2004, Google posted on a giant billboard along Highway 101 ...
- 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)字符串+素数
Google Recruitment PAT-1152 本题最需要注意的是最后输出要以字符串形式输出,否则可能会出现前导0的情况. /** * @Author WaleGarrett * @Date ...
- 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 分)
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 ...
- 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
题干前半略. Input Specification: Each input file contains one test case. Each case first gives in a line ...
随机推荐
- http-runtime属性
配置httpRuntime也可以让FileUpload上传更大的文件,不过设置太大了会因用户将大量文件传递到该服务器而导致的拒绝服务攻击(属性有说明) 属性 属性 选项 说明 appRequestQu ...
- zookeeper协调技术
本文转自http://www.cnblogs.com/wuxl360/p/5817471.html 感谢作者 一.分布式协调技术 在给大家介绍ZooKeeper之前先来给大家介绍一种技术——分布式协调 ...
- Centos7安装Rancher
docker pull rancher/server:v1.6.14 启动一个单实例的Rancher. docker run -d --restart=unless-stopped -p 8080:8 ...
- Android入门之文件系统操作(二)文件操作相关指令
(一)获取总根 File[] fileList=File.listRoots(); //返回fileList.length为1 //fileList.getAbsolutePath()为"/ ...
- 学界| UC Berkeley提出新型分布式框架Ray:实时动态学习的开端—— AI 应用的系统需求:支持(a)异质、并行计算,(b)动态任务图,(c)高吞吐量和低延迟的调度,以及(d)透明的容错性。
学界| UC Berkeley提出新型分布式框架Ray:实时动态学习的开端 from:https://baijia.baidu.com/s?id=1587367874517247282&wfr ...
- Opencv保存摄像头视频&&各种编码器下视频文件占用空间对比
打开视频文件或摄像头视频需要使用Opencv中的VideoCapture类,保存视频或摄像头视频到本地磁盘,需要使用Opencv中的VideoWriter类,使用都很简单,这篇文章就记录一下Video ...
- B1041 [HAOI2008]圆上的整点 数学
这个题一开始看着没什么思路,但是一看题解就明白了不少,主要是数学证明,代码很好写. 贴个网址: hzwer 题干: 题目描述 求一个给定的圆(x^+y^=r^),在圆周上有多少个点的坐标是整数. 输入 ...
- B1800 [Ahoi2009]fly 飞行棋 数学模拟
20分钟一遍AC,大水题,我的算法比较复杂,但是好理解,就是找可以凑出来一半周长的点来暴力枚举就行了. 题干: Description 给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依 ...
- IJ-Error:常见错误
ylbtech-IJ-Error:常见错误 1.返回顶部 1. This application has no explicit mapping for /error, so you are seei ...
- python3用list实现栈
工作中遇到的需求,****代表标签数据别的信息: D01 ******** 1 ******** D01 ******** 2 ******** D01 ******** 3 ******** D01 ...