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
- Recruitment-- JAVA Engineer--ShanghaiUIJavaAI
- Recruitment-- Senior Java Developer--ShanghaiUIJavaDeveloperAI
- Google 面試題 | 分餅乾Go面試題
- Recruitment: J2EE Technical Lead -- ShanghaiUIAI
- C#分頁 訪googleC#Go
- Recruitment-Senior J2EE Developer-ShanghaiUIDeveloperAI
- Google Play強制所有手遊分級,廣告也要分級Go
- 1152:最大數max(x,y,z)(C C++)C++
- google測試分享-分層測試Go
- google對計算機的分類Go計算機
- ReThink Recruitment:2012年英國APP開發者平均年薪增長27% 達到70萬元UIAPP
- URAL 1152 False Mirrors(簡單的狀態壓縮dp)False
- On-site question removal + direct interview | Meituan technical school recruitment live broadcast is here!REMViewUIAST
- Recruitment Java Programmer (荷蘭遊戲公司高薪聘請後臺主程)UIJava遊戲高薪
- Google搜尋為什麼不能無限分頁?Go
- Google的Logo(第二部分)Go
- Google的應用(第二部分)Go
- Google:2014年1月Android系統分佈圖 Jelly Bean接近60%GoAndroidBean
- google在2012年末將發售google眼鏡Go
- Google的Logo(第一部分)Go
- GfK:2015年Q4全球智慧手機銷售額1152億美元 同比下跌0.2%
- InstallShield安裝時出現“1152:error extracting"的解決方案Error
- Google Play將引入年齡分級和人工稽核機制Go
- Google:2012年Google搜尋熱榜: 江南Style入圍Go
- Google:2011年Google+ 使用者達到9000萬Go
- 2020年通過Google訪問盜版網站的流量銳減三分之一Go網站
- Google 2019開發者大會Go
- Google的70/20/10分配法則Go
- Google I/O Extend 2018Go
- Google 2020開發者大會Flutter專題GoFlutter
- Google:2015年Google Play最佳應用和最佳遊戲應用Go遊戲
- 影像分類丨Inception家族進化史「GoogleNet、Inception、Xception」Go
- Google Play更新打分規則:新版本評分影響更大Go
- 壟斷者 Google Chrome 若被迫分拆,誰將會接盤?GoChrome
- Google 400多號的科學家團隊專案分佈Go
- Google kickstart 2022 Round A題解Go
- Google 2018年趣味盤點Go