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 ...
随机推荐
- 创建 Visual Studio 2017 离线安装
代码示例: vs_Enterprise.exe --layout E:\VS2017LAYOUT --add Microsoft.VisualStudio.Workload.NetCoreTools ...
- react组件实现扩展知识
react-redux redux-thunk 实现异步action, ajax,定时器 redux-gen 利用生成器,实现middleware react-router-redux react-r ...
- flask 电子邮件Flask-Mail
电子邮件 在web程序中,经常会需要发送电子邮件.比如,在用户注册账户时发送确认邮件:定期向用户发送热门内容或是促销信息等等.在Web程序中发送电子邮件并不复杂,借助扩展Flask-Mail或是第三方 ...
- Java面向对象概述和三大特性
Java 是面向对象的高级编程语言,类和对象是 Java 程序的构成核心.围绕着 Java 类和 Java 对象,有三大基本特性:封装是 Java 类的编写规范.继承是类与类之间联系的一种形式.而多态 ...
- 2018-2019-2 20165215《网络对抗技术》Exp5 MSF基础应用
目录 实验内容 实验原理 实验步骤 (一)一个主动攻击实践 ms08_067(成功) (二)一个针对浏览器的攻击 ms14_064(成功) (三)一个针对客户端的攻击 Adobe(成功) CVE-20 ...
- ldap认证jupyter notebook
虽然jupyter hub是支持ldap的,见ldapauthenticator: 但是登录成功后似乎要以登录用户名启动notebook,而登录用户在服务器上不存在,于是500了: 在服务器上通过pa ...
- java网络编程学习之NIO模型
网上对NIO的解释有很多,但自己一直没有理解,根据自己的理解画出下面这个图,有什么不对的地方,欢迎留言指出. 理解是,客户端先与通过通道Channel与连接(注册到服务器端),然后再传送数据,服务器端 ...
- FIT2096 Assignment 2 2019
FIT2096 Assignment 2 2019_v1.2.docx 9/04/2019 11:34 AMPage 1 | 4FIT2096 Assignment 2 2019Transformat ...
- 尝试解决IDea 启动项目后,后台疯狂输出日志。
今天启动项目的时候,昨天下班前还好好,然后今天就炸了.后台疯狂输出日志.. 就类似这种,大批量的刷.其实项目已经正常启动了,就是疯狂的刷日志. 2019-03-29 08:42:53 [DEBUG] ...
- python文件读书笔记
一.打开文件 1 f=open('text.txt',r) 二.读取文件 print(f.read) 三.关闭文件 f.close() 比较好用的是运用with with open('text.tx ...