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 <iostream>
#include <cmath>
#include <cstdlib> using namespace std;
//judge is prime
bool isPrime(int num){
if(num==||num==) return true;
for(int i=;i<=sqrt(num);i++){
if(num%i==) return false;
}
return true;
} int main()
{
int len,prime_len;string str;
cin>>len>>prime_len>>str;
for(int i=;i<=(len-prime_len);i++){
int tmp=atoi(str.substr(i,prime_len).data());
if(isPrime(tmp)){
cout<<str.substr(i,prime_len);
system("pause");
return ;
}
}
cout<<;
system("pause");
return ;
}

最新文章

  1. PCB Layout高速电路设计小知识点
  2. TCMalloc的使用
  3. people 0919
  4. php 数组排序 sort asort ksort
  5. jQuery插件手把手教会(二)
  6. android 中FragmentActivity中模拟返回键返回上一个Activity效果
  7. [Cocos2d-x]布局与定位
  8. Singleton模式(Singleton创建类型)c#简单的例子
  9. vue.js之组件篇
  10. C# out ref 用法总结
  11. HTML5冲刺
  12. Python3学习之路~7.3 反射
  13. DataGrip for Mac破解步骤详解 亲测好用
  14. 非常详细的Docker学习教程
  15. 4th Dec 2018
  16. WebAssembly是什么?
  17. C语言入门:03.关键字、标识符、注释
  18. RabbitMQ集群和高可用配置
  19. WCF 统一处理异常利用行为服务扩展
  20. 献给java求职路上的你们

热门文章

  1. hello/hi的简单的网络聊天程序
  2. Docker-compose容易忽略的使用细节
  3. 虚拟机中CentOS 7 x64图形化界面的安装
  4. ffmpeg学习笔记-Linux下编译Android动态库
  5. 最新 汇通达java校招面经 (含整理过的面试题大全)
  6. jqGrid清空表格
  7. XKC&#39;s basketball team【线段树查询】
  8. Django-filter报错:__init__() got an unexpected keyword argument &#39;name&#39;
  9. 把Javascript 对象转换为键值对连接符字符串的方法总结
  10. 【AtCoder】AGC002