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
簡單,一開始看成k<=10了,因為int最多是10的9次,所以string轉ll還讓我頭疼了一番,最後有可能是0003這樣的數,所以你要補0或者以string形式輸出
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
bool isPrime(int x){
if(x <= 1) return false;
int Sqrt = int(sqrt(x));
for(int i =2; i <= Sqrt; i++){
if(x%i == 0) return false;
}
return true;
}
int main(){
int n,k;
string s;
cin>>n>>k;
cin>>s;
for(int i = 0; i <= n-k; i++){
string sub = s.substr(i,k);
int x = stoi(sub);
if(isPrime(x)){
cout<<sub;
return 0;
}
}
cout<<"404";
return 0;
}
相關文章
- PAT 甲級 1152 Google Recruitment (20分)GoUI
- 1152:最大數max(x,y,z)(C C++)C++
- On-site question removal + direct interview | Meituan technical school recruitment live broadcast is here!REMViewUIAST
- google chromeGoChrome
- google search grammerGo
- vim Google style formatGoORM
- Google搜尋技巧Go
- Google multitask模型SNRGo模型
- Google 真賤格Go
- GOOGLE RANKBRAIN 完整指南GoAI
- Google正在失去DeepMind?Go
- Google命名規範Go
- Google Colab的使用Go
- 模仿Google News的TabLayoutGoTabLayout
- 如何使用Google服務Go
- Google I/O Extend 2018Go
- Deploy Google BBR on CentOS 7GoCentOS
- 正確高效使用 GoogleGo
- Google關鍵字工具Go
- Google Pay接入流程Go
- google guava集合之MultisetGoGuava
- google smtp 郵箱配置Go
- Google 正式開源 ParanoidGo
- Google JavaScript 風格指南GoJavaScript
- time-based基於google key生成6位驗證碼(google authenticator)Go
- Google:Google Cloud再次打破了百萬億位的圓周率計算紀錄GoCloud
- Spring Boot整合Google Bard - Web介面訪問Google AI聊天機器人Spring BootGoWebAI機器人
- IC Insights:預計2021年Q3全球前15名半導體公司營收1152億美元 同比增長7%營收
- Ten Tips for Smarter Google Searches (十個更聰明使用 Google 搜尋的技巧)Go
- Google Guava Stopwatch(計時器)GoGuava
- Google 2018年趣味盤點Go
- DDD for everyone - Google 幻燈片Go
- WEB.DEV – Google SEO 工具WebdevGo
- Google新人的成長思考Go
- Google分析language垃圾資訊Go
- [Guava] Google Guava 集合工具類GuavaGo
- Google 單元測試框架Go框架
- Google Adsense 推出“AD Intent”功能GoIntent