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 404instead. 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:

  1. 20 5
  2. 23654987725541023819

Sample Output 1:

  1. 49877

Sample Input 2:

  1. 10 3
  2. 2468024680

Sample Output 2:

  1. 404
  2.  
  3. 那个前导0是真的坑 学到了
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <string.h>
  5. #include <cstring>
  6. using namespace std;
  7. string s;
  8. int _deal(int x)
  9. {
  10. if(x<=) return ;
  11. int flag=;
  12. for(int i=;i*i<=x;i++){
  13. if(x%i==){
  14. flag=;
  15. break;
  16. }
  17. }
  18. return flag;
  19. }
  20. int main()
  21. {
  22. int n,m;
  23. while(cin>>n>>m){
  24. cin>>s;
  25. int flag=,sum=,t=;
  26. for(int i=;i<=n-m;i++){
  27. sum=,t=;
  28. for(int j=i+m-;j>=i;j--){
  29. sum+=t*int(s[j]-'');
  30. t*=;
  31. }
  32. if(_deal(sum)){
  33. flag=;
  34. printf("%0*d\n",m,sum);//坑啊
  35. break;
  36. }
  37. }
  38. if(!flag)cout<<""<<endl;
  39. }
  40. return ;
  41. }

PAT (Advanced Level) Practice 1152 Google Recruitment (20 分)的更多相关文章

  1. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  2. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  3. PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...

  4. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

  5. PAT (Advanced Level) Practice 1120 Friend Numbers (20 分) (set)

    Two integers are called "friend numbers" if they share the same sum of their digits, and t ...

  6. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  7. PAT甲级:1152 Google Recruitment (20分)

    PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...

  8. PAT甲级——1152.Google Recruitment (20分)

    1152 Google Recruitment (20分) In July 2004, Google posted on a giant billboard along Highway 101 in ...

  9. 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 ...

随机推荐

  1. lwip1.4.1需要的文件

    1.4.1版本一共必须25个文件,如下,接下来,要看如何将2.0.2用起来 以上是必须的lwip原始的文件, 此外,还需要一些其它文件 Keil uVision5包含路径配置:

  2. Android O 8.0 奥利奥

    Android O 8.0 奥利奥 1.画中画, 2.智能文本选择(Smart Text Selection), 3.notification dots, 4.自动填写(Auto-Fill)   4. ...

  3. Vue使用v-for显示列表时,数组里的item数据更新,视图中列表不同步更新的解决方法

    由于初始化类型错误导致的不更新,代码是这样的: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  4. thinkphp v5.1.36 LTS 如果设置跨域访问

    修改route/route.php中的路由例如 Route::get('new/:id', 'News/read') ->ext('html') ->header('Access-Cont ...

  5. clr via c# 运行时序列化

    1,快速了解序列化----windows IO 系统,FileStream,BinaryFormatter,SoapFormatter--不支持泛型. public class SerializeRe ...

  6. Linux学习Day5:Vim编辑器、配置网卡、配置Yum软件仓库

    今天首先学习Vim编辑器的使用,通过它可以对Linux系统的文件进行编写和修改.在Linux系统中一切都是文件,所以熟练掌握Vim编辑器的使用十分重要.最后通过配置主机网卡的实验,来加深Vim编辑器中 ...

  7. 邓士鹏【MySql大全】

    禁止使用系统关键字: typename 1.计算两个日期的时间差函数 SELECT TIMESTAMPDIFF(MONTH,'2009-10-01','2009-09-01'); interval可是 ...

  8. LoaderTest加载测试用例的方法总结

    加载用例,可以用suite.addTest(测试类名("测试函数名"))实现,也可用过suit.addTest(loader.Loader....)实现,一下针对Loader的三个 ...

  9. win7无法访问局域网中其它计算机:0x80070035

    https://zhidao.baidu.com/question/304232217962584564.html https://jingyan.baidu.com/article/ff411625 ...

  10. MySQL安装图解及调试

    MySQL 5.7安装图解 注意:请确认系统是否已安装Microsoft Visual C++2013 Redistributable基本运行库,开始>控制面板>卸载程序中查看,如图所示: ...