当前位置:网站首页>1094 谷歌的招聘 (20 分)
1094 谷歌的招聘 (20 分)
2022-08-03 05:09:00 【破烂摆烂人】
2004 年 7 月,谷歌在硅谷的 101 号公路边竖立了一块巨大的广告牌(如下图)用于招聘。内容超级简单,就是一个以 .com 结尾的网址,而前面的网址是一个 10 位素数,这个素数是自然常数 e 中最早出现的 10 位连续数字。能找出这个素数的人,就可以通过访问谷歌的这个网站进入招聘流程的下一步。
prime.jpg
自然常数 e 是一个著名的超越数,前面若干位写出来是这样的:e = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003059921… 其中粗体标出的 10 位数就是答案。
本题要求你编程解决一个更通用的问题:从任一给定的长度为 L 的数字中,找出最早出现的 K 位连续数字所组成的素数。
输入格式:
输入在第一行给出 2 个正整数,分别是 L(不超过 1000 的正整数,为数字长度)和 K(小于 10 的正整数)。接下来一行给出一个长度为 L 的正整数 N。
输出格式:
在一行中输出 N 中最早出现的 K 位连续数字所组成的素数。如果这样的素数不存在,则输出 404。注意,原始数字中的前导零也计算在位数之内。例如在 200236 中找 4 位素数,0023 算是解;但第一位 2 不能被当成 0002 输出,因为在原始数字中不存在这个 2 的前导零。
输入样例 1:
20 5
23654987725541023819
输出样例 1:
49877
输入样例 2:
10 3
2468024680
输出样例 2:
404
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char num[1000] ;
int l , k ;
scanf("%d %d",&l,&k) ;
scanf("%s",&num) ;
int i , j ;
for( i = 0 ; i <= l - k ; i++ ){
int sum = 0 , flag = 1 ;
for( j = i ; j < i + k ; j++ ){
sum = ( num[j] - '0') + sum*10 ;
}
if(sum==0||sum==1){
flag = 0 ;
}
for( j = 2 ; j <= sqrt(sum) ; j++ ){
if( sum%j == 0 ){
flag = 0 ;
break ;
}
}
if( flag == 1 ){
for( j = i ; j < i + k ; j++ ){
printf("%c",num[j]) ;
}
break ;
}
}
if( i > l - k ){
printf("404") ;
}
return 0;
}
边栏推荐
- 数字化时代,企业如何建立自身的云平台与商业模式的选择?
- Common fluorescent dyes to modify a variety of groups and its excitation and emission wavelength data in the data
- PotPlayer实现上班摸鱼电视自由
- Kotlin-Flow常用封装类:StateFlow的使用
- 【Harmony OS】【FAQ】Hongmeng Questions Collection 1
- IO进程线程->线程->day5
- Harmony OS Date ano UI 】 【 】 the basic operation
- 索引创建、删除与使用
- 荧光标记多肽FITC/AMC/FAM/Rhodamine/TAMRA/Cy3/Cy5/Cy7-Peptide
- idea使用@Autowired注解爆红原因及解决方法
猜你喜欢

typescript39-class类的可见修饰符

How to use the interface management tool YApi?Beautiful, easy to manage, super easy to use

内部类、static关键字、final

Talking about GIS Data (6) - Projected Coordinate System

接口测试框架实战(四)| 搞定 Schema 断言

链动2+1模式简单,奖励结构丰厚,自主裂变?

Shell条件语句判断

Interface test practice | Detailed explanation of the difference between GET / POST requests

社交电商:链动2+1模式,为什么能在电商行业生存那么久?

Jmeter 模拟多用户登录的两种方法
随机推荐
[Harmony OS] [ARK UI] ETS context basic operations
JS bottom handwriting
在竞争白热化的电商行业,链动2+1为什么还有企业在用
自组织是管理者和成员的双向奔赴
Interface test framework combat (1) | Requests and interface request construction
【Harmony OS】【ARK UI】ets use startAbility or startAbilityForResult to invoke Ability
shell script loop statement
MCM箱模型建模方法及大气O3来源解析
【软件工程之美 - 专栏笔记】35 | 版本发布:软件上线只是新的开始
c语言结构体中的冒泡排序
typescript45-接口之间的兼容性
FileZilla 搭建ftp服务器
技术分享 | 接口自动化测试中如何对xml 格式做断言验证?
typescript40-class类的保护修饰符
C#异步和多线程
IO进程线程->线程->day5
typescript46-函数之间的类型兼容性
Two ways to simulate multi-user login in Jmeter
数字孪生园区场景中的坐标知识
Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection