1152 Google Recruitment (20 point(s))

android学习——使用SAX、DOM 和 PULL 解析xml文件,及使用pull生成xml文件 sax DefaultHandler 实现了 Handler接口,使用 sax解析时,只需要继承下 package com.hujl.parserxml.service; import java.util.ArrayList; import java.util.List; import org.xml.sax.Attributes; import org.xml.sax.SAXExce 阅读详情

1152 Google Recruitment (20 point(s))

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.

prime.jpg

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,可以判定那么大的素数吗,其实即使是1e10,也只需要1e5次运算,稍微想想就知道考虑是不必要的。

注意点:

注意如果输出的素数有前导0,也要输出,否则case#2会WA(18分);

#include<iostream>
#include<cstring>
using namespace std;
string s,num;int L,K;
bool isPrime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0) return false;
	}
	return true;
}
int string2int(string s){
	int ans = 0;
	for(int i=0;i<s.length();i++){
		ans = ans*10+s[i]-'0';
	}
	return ans;
}
int main(void){
	cin>>L>>K>>s;
	for(int i=0;i+K<=s.length();i++){
		num = s.substr(i,K);
		int x = string2int(num);
		if(isPrime(x)){
			cout<<num<<endl;
			return 0;
		} 
	}
	cout<<"404"<<endl;
	return 0;
}

 

PADS VX2.7学习记录06-PADS Router软件功能操作 阅读详情

相关推荐

手把手教你逆向分析某里系bx-ua参数(以225版本为例)

本文详细解析了某里系应用bx-ua参数的逆向工程实战方法,重点拆解其三层加密体系(二进制加密、字符替换和Base64编码)。通过工具链配置和实战案例,帮助开发者掌握逆向分析技巧,适用于合法合规的安全研究和加密技术评估场景。

weixin_33220360的博客 413

2018年冬季PAT甲级 7-1 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 p...

Hickey_Chen的博客 474

数据结构之栈(Stack)的实现详解

堆栈是一种线性数据结构,其插入新元素和删除现有元素都发生在堆栈的顶部。栈(Stack)按照"后进先出"(Last-In-First-Out,LIFO)的原则存储和访问数据。栈类似于现实生活中的堆叠物体,比如一摞书或者一堆盘子。

swadian2008的博客 3813

论坛网址大全

http://people.sina.com.cn/forum.html 新浪网论坛 http://club.sohu.com/ 搜狐社区 http://bj.163.com/ 网易北京社区 http://bbs.tom.com/bbs.php TOM海云天论坛 http://bbs.china.com/ 中华网论坛 http://forum.21cn.com/ 21CN.COM论坛 ...

java开发指南博客 【转载】 9002

多旋翼飞行器设计与控制·Pixhawk4以及外部设备接线(笔记004)

笔记主要来源:Pixhawk 4 接线快速入门 目录 一、Pixhawk 4 的各个接口 二、接线图概览(重要传感器及外围设备) 三、飞控、GPS的安装和方向 四、电源 五、无线电遥控 六、数传电台(可选) 七、SD Card(可选) 八、电机以及其他外设 一、Pixhawk 4 的各个接口 FMU:Flight Management Unit 飞行管理组件 主 FMU 处理器:STM32F765 32 位 Arm® Cortex®-M7,216MHz,2MB...

猪猪的博客 1万+

深入解析XTEA加密算法的核心机制与优化策略

本文深入解析XTEA加密算法的核心机制与优化策略,详细介绍了XTEA在嵌入式系统和资源受限环境中的优势,包括其高效的加解密速度和低资源消耗。文章还探讨了XTEA的轮函数设计、关键参数优化策略以及实战应用中的性能对比,为开发者提供了安全增强方案和优化技巧。

k8l9m0n的博客 243

JavaScript中的date对象,定时器

JavaScript中的date对象,定时器

m0_64494670的博客 493

xxl-job快速入门(最全)

某电商平台需要每天上午10点,下午3点,晚上8点发放一批优惠券某银行系统需要在信用卡到期还款日的前三天进行短信提醒某财务系统需要在每天凌晨0:10分结算前一天的财务数据,统计汇总以上场景就是任务调度所需要解决的问题任务调度是为了自动完成特定任务,在约定的特定时刻去执行任务的过程XXL-Job:是大众点评的分布式任务调度平台,是一个轻量级分布式任务调度平台, 其核心设计目标是开发迅速、学习简单、轻量级、易扩展大众点评目前已接入XXL-JOB,该系统在内部已调度约100万次,表现优异。

gnwu1111的专栏 1702

网词解释&耽美术语

一.论坛日常用语: 1、BBS:①Bulletin Board System的缩写,指电子公告板系统,国内统称论坛。②波霸,Big-Breasted Sister的缩写。 2、斑竹:版主,也可写作板猪。由于拼音输入造成的美妙谐音。副版主叫“板斧”。 3、马甲:注册会员又注册了其他的名字,这些名字统称为马甲,与马甲相对的是主ID。 例句:青眉建议斑竹进行版务管理时,不可以用马甲发言。 4、菜鸟:原指

零-专栏 8万+

DeepSeek+Dify实战:零代码构建智能SQL生成器

本文详细介绍了如何利用DeepSeek和Dify零代码构建智能SQL生成器,帮助非技术人员通过自然语言查询数据库。文章涵盖从数据准备、知识库设计到Agent配置的全流程,并提供了优化技巧和实际应用案例,显著提升团队数据查询效率。

weixin_29311017的博客 419

CANOE-介绍 @014-基于CAPL的Someip测试(CANOE 15.0/16.0/17.0)【草稿】发送事件、方法

摘要:本文介绍了使用CANoe 16.0及更高版本配置SOME/IP测试环境的方法,包括硬件连接、工程配置和CAPL代码实现。SOME/IP是一种面向服务的车载通信协议,支持服务发现、事件推送和方法调用。文章详细说明了网络拓扑配置、数据库文件加载等步骤,并提供了CAPL代码示例,展示如何初始化多个应用端点(15个不同端口)和服务实例(73个服务),通过SomeIpOpenLocalApplicationEndpoint和SomeIpCreateProvidedServiceInstance函数实现。配置过程

沿流不止 424

【PAT】A1152 Google Recruitment (20 point(s))

文章目录A1152 Google Recruitment (20 point(s))Input Specification:Output Specification:Sample Input 1:Sample Output 1:Sample Input 2:Sample Output 2: A1152 Google Recruitment (20 point(s)) In July 2004, G...

Duke 203

贝叶斯网络 (Bayesian Networks) 原理与代码实例讲解

贝叶斯网络 (Bayesian Networks) 原理与代码实例讲解 1. 背景介绍 1.1 什么是贝叶斯网络? 贝叶斯网络(Bayesian Networks)是一种基于概率论的图形模型,用于表示随机

AI天才研究院 1334

1152 Google Recruitment (20 point(s))

切分找素数。

Bonstoppo 258

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

1152 Google Recruitment (20point(s)) - C语言 PAT 甲级

* 截取字符串,转换成数字,判断是否为素数

有三只土豆 396

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

PAT_甲级_1152 Google Recruitment (20point(s)) (C++)【字符串处理/寻找质数】

目录 1,题目描述 题目大意 2,思路 3,AC代码 4,解题过程 第一搏 第二搏 1,题目描述 recruitment:招募,招聘; Sample Input 1: 20 5 23654987725541023819 Sample Output 1: 49877 Sample Input 2: 10 3 2468024680 Sa...

&再见萤火虫&的博客 788

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

1152 Google Recruitment 20

题目 题意:给出一个L(&lt;=1000)位的数字,找出其中的可表示为素数的最左边的K(&lt;10)个连续数字。如果找到,就输出这个数字,找不到就输出404。如果数字有前导0,也要输出。 思路:由于K&lt;10,那么可以直接用int表示这个数字。这样最简单的做法就是K个数字为一段,从左向右检查。转为int检查是否为素数。 历程:先交了一份下面的代码,测试点2答案错误。 #include &l...

一起努力 919

1152 Google Recruitment【及其简单的一道题,说说一些注意的测试点】

1152 Google Recruitment (20分) OJ入口 注意的点: 1、在遍历输入的字符串中,注意边界的处理,不要忘记等号。 2、输出的时候注意00004这种情况,前面的0也是要输出的。 #include<bits/stdc++.h> using namespace std; string num; bool isprime(int num){ if(num==1||num == 0) return false; for(int i=2;i*i<=num;i++){

目标:NLP算法工程师 560

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

92377 222

1152 Google Recruitment (20 point(s)

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

zclimou的博客 207

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

Imagirl1的博客 776

舞文弄墨

昨晚梦见自己反复吟诵一首诗,很有意境的样子,醒来却一点都记不得了。今天端午节,整理下我乱写的诗文,支持屈原 !  -----------------------------------------------------------------------------------------------------------------------------------------------

镜像之城 2482

国内的部分免费论坛程序汇总

1、Vbb(PHP+MYSQL) http://www.chinavbb.com/ 2、LB5000(CGI) http://www.leoboard.com/cgi-bin/leoboard.cgi 3、bbs3000 (CGI) http://www.bbs3000.com/cgi-bin/bbs3000/list.cgi 4、动网(ASP+ACCESS) http://www.dvbbs.n

米灰色的天空~~ 2万+

http://bbs.youkuaiyun.com/topics/390626193的最后解决办法。

哈哈! 最后的最后,终于搞定了,一个项目里面配置了2个服务,SOAP Service 和REST Service . 重点在于:service的类头上要加:    [AspNetCompatibilityRequirements(         RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]     [

lyh_mzsm的专栏 8260

国内几款通用论坛程序简介和比较

=ASP论坛= 动网 - 国内最多人使用的ASP论坛,现在官方论坛上注册人数已经有50万,当然越多人用就越多人研究,他的完善也就越快.插件最多,风格也最多.D-SHOW,云上社区,酷神都是动网很叼的风格制作者. 官方论坛: http://bbs.dvbbs.net kerling评:动网bbs有sql与access两个版本,sql为商业版,access为免费版,综合起来看凭着动网的品牌与windo...

regedit123的博客 1215

论坛列表

来自:http://www.wujianrong.com/archives/2009/06/post-1677.html   http://people.sina.com.cn/forum.html 新浪网论坛000015 002 http://club.sohu.com/ 搜狐社区000020 003 http://bj.163.com/ 网易北京社区000043 004 http://bb...

天生我材必有用,千金散尽还复来 3180
上一篇: 1147 Heaps (30 point(s))
下一篇: 1144 The Missing Number (20 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值