当前位置:网站首页>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;
}
边栏推荐
- 接口测试如何准备测试数据
- Kotlin-Flow常用封装类:StateFlow的使用
- 技术分享 | 接口自动化测试中如何对xml 格式做断言验证?
- UV decomposition of biotin - PEG2 - azide | CAS: 1192802-98-4 biotin connectors
- 数据库基本概述与SQL概述
- typescript47-函数之间的类型兼容性
- JS底层手写
- 【HMS core】【Ads Kit】华为广告——海外应用在国内测试正式广告无法展示
- 【Harmony OS】【ARK UI】ets使用startAbility或startAbilityForResult方式调起Ability
- 【HMS core】【Ads Kit】Huawei Advertising——Overseas applications are tested in China. Official advertisements cannot be displayed
猜你喜欢

测试人员的价值体现在哪里

数字化时代,企业如何建立自身的云平台与商业模式的选择?

Apache DolphinScheduler版本2.0.5分布式集群的安装

How to prepare for the test interface test data

Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures

Two ways to simulate multi-user login in Jmeter

常见荧光染料修饰多种基团及其激发和发射波长数据一览数据

BIOTIN ALKYNE CAS:773888-45-2价格,供应商

在树莓派上搭建属于自己的网页(2)

Windows 安装PostgreSQL
随机推荐
Talking about GIS Data (5) - Geographic Coordinate System
数据库基本概述与SQL概述
JS底层手写
typescript43-类型兼容性说明
Tributyl-mercaptophosphane "tBuBrettPhos Pd(allyl)" OTf), 1798782-17-8
软件开发的最大的区别是什么?
CobalStrike(CS)基础超级详细版
Technology Sharing | How to do assertion verification for xml format in interface automation testing?
presto安装部署教程
设计模式——组合模式、享元模式(Integer缓存)(结构型模式)
typescript42-readonly修饰符
测试人员的价值体现在哪里
typescript49-交叉类型
【开发者必看】【push kit】推送服务服务典型问题合集2
Modified BiotinDIAZO-Biotin-PEG3-DBCO|diazo-biotin-tripolyethylene glycol-diphenylcyclooctyne
tag单调栈-单调栈预备知识-lt.739. 每日温度
unity2D横板游戏教程6-敌人AI以及受击动画
【精讲】利用原生js实现todolist
数字化时代,企业如何建立自身的云平台与商业模式的选择?
【Biotin Azide|cas:908007-17-0】Price_Manufacturer