Chinaunix首页 | 论坛 | 博客
  • 博客访问: 504295
  • 博文数量: 137
  • 博客积分: 3874
  • 博客等级: 中校
  • 技术积分: 1475
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-05 10:50
文章分类

全部博文(137)

文章存档

2011年(37)

2010年(100)

分类:

2010-07-16 21:18:12

MM找实习,看面试宝典,给我出了道逻辑题,据说是微软的面试题:
题是这样的
有三个人 
一个是你,一个是和先生,一个是积先生 
你先想好两个整数(2到99之间) 
然后将两数之和告诉和先生,两数之积告诉积先生 
下面是和先生和积先生的对话 
和先生:我知道你不知道这两个数是什么,我也不知道这两个数是什么 
积先生:我现在知道这两个数是什么了 
和先生:我现在也知道了 
看了上面的对话,可以推断出这两个数是什么 
以下是百度贴吧一个人的答案:
因为和先生知道两数之和,却由此推断积先生不知道两个数,所以说两数之和和先生一定不能拆分成两个质数的和,即m,n不可能都是质数,且m,n中不会有大于50的质数,否则的话m*n可以唯一分解,积先生知道了m,n的积就一定可以知道m,n了。 

积先生从和先生的言语中能够判断出的信息是: 
1。m,n不会全是质数; 
2。m,n中不会有大于50的质数; 
3。m,n之和不能拆成两个质数的和; 
4。因为和先生自己也不知道这两个数是什么,所以这两个数的和一定小于99+98,否则和先生就可以知道这两个数是什么了。 

满足以上条件的 和=m+n有以下的可能: 

11 
17 
23 
27 
29 
35 
37 
41 
47 
196 

然后积先生根据自己掌握的 积=m*n立即算出m,n,这说明 积=m*n是具有以下性质的特殊数字: 

根据这个特殊的积,当和先生取上面的那些值的时候,只有一种和的取值使得方程 
m+n=和, 
m*n=积 
在[2,99]内有唯一的整数解。 

根据这个性质计算出的积先生有以下的情况: 

积 = 18, 和= 11, m = 2, n = 9 
积 = 24, 和= 11, m = 3, n = 8 
积 = 28, 和= 11, m = 4, n = 7 
积 = 50, 和= 27, m = 2, n = 25 
积 = 52, 和= 17, m = 4, n = 13 
积 = 54, 和= 29, m = 2, n = 27 
积 = 76, 和= 23, m = 4, n = 19 
积 = 92, 和= 27, m = 4, n = 23 
积 = 96, 和= 35, m = 3, n = 32 
积 = 100, 和= 29, m = 4, n = 25 
积 = 110, 和= 27, m = 5, n = 22 
积 = 112, 和= 23, m = 7, n = 16 
积 = 114, 和= 41, m = 3, n = 38 
积 = 124, 和= 35, m = 4, n = 31 
积 = 130, 和= 23, m = 10, n = 13 
积 = 138, 和= 29, m = 6, n = 23 
积 = 140, 和= 27, m = 7, n = 20 
积 = 148, 和= 41, m = 4, n = 37 
积 = 150, 和= 35, m = 5, n = 30 
积 = 152, 和= 27, m = 8, n = 19 
积 = 154, 和= 29, m = 7, n = 22 
积 = 160, 和= 37, m = 5, n = 32 
积 = 162, 和= 27, m = 9, n = 18 
积 = 168, 和= 29, m = 8, n = 21 
积 = 170, 和= 27, m = 10, n = 17 
积 = 172, 和= 47, m = 4, n = 43 
积 = 174, 和= 35, m = 6, n = 29 
积 = 176, 和= 27, m = 11, n = 16 
积 = 182, 和= 27, m = 13, n = 14 
积 = 186, 和= 37, m = 6, n = 31 
积 = 190, 和= 29, m = 10, n = 19 
积 = 196, 和= 35, m = 7, n = 28 
积 = 198, 和= 29, m = 11, n = 18 
积 = 204, 和= 29, m = 12, n = 17 
积 = 208, 和= 29, m = 13, n = 16 
积 = 216, 和= 35, m = 8, n = 27 
积 = 232, 和= 37, m = 8, n = 29 
积 = 234, 和= 35, m = 9, n = 26 
积 = 238, 和= 41, m = 7, n = 34 
积 = 246, 和= 47, m = 6, n = 41 
积 = 250, 和= 35, m = 10, n = 25 
积 = 252, 和= 37, m = 9, n = 28 
积 = 270, 和= 37, m = 10, n = 27 
积 = 276, 和= 35, m = 12, n = 23 
积 = 280, 和= 47, m = 7, n = 40 
积 = 288, 和= 41, m = 9, n = 32 
积 = 294, 和= 35, m = 14, n = 21 
积 = 304, 和= 35, m = 16, n = 19 
积 = 306, 和= 35, m = 17, n = 18 
积 = 310, 和= 41, m = 10, n = 31 
积 = 322, 和= 37, m = 14, n = 23 
积 = 336, 和= 37, m = 16, n = 21 
积 = 340, 和= 37, m = 17, n = 20 
积 = 348, 和= 41, m = 12, n = 29 
积 = 364, 和= 41, m = 13, n = 28 
积 = 370, 和= 47, m = 10, n = 37 
积 = 378, 和= 41, m = 14, n = 27 
积 = 390, 和= 41, m = 15, n = 26 
积 = 396, 和= 47, m = 11, n = 36 
积 = 400, 和= 41, m = 16, n = 25 
积 = 408, 和= 41, m = 17, n = 24 
积 = 414, 和= 41, m = 18, n = 23 
积 = 418, 和= 41, m = 19, n = 22 
积 = 442, 和= 47, m = 13, n = 34 
积 = 462, 和= 47, m = 14, n = 33 
积 = 480, 和= 47, m = 15, n = 32 
积 = 496, 和= 47, m = 16, n = 31 
积 = 510, 和= 47, m = 17, n = 30 
积 = 522, 和= 47, m = 18, n = 29 
积 = 532, 和= 47, m = 19, n = 28 
积 = 540, 和= 47, m = 20, n = 27 
积 = 546, 和= 47, m = 21, n = 26 
积 = 550, 和= 47, m = 22, n = 25 
积 = 552, 和= 47, m = 23, n = 24 
积 = 9604, 和= 196, m = 98, n = 98 

最后积先生说出自己已经知道m,n以后,和先生也说自己知道了m,n,这说明和先生根据自己手中的两数之和可以推断出唯一的m,n来。 

因此还要去除上面的情况中重复用到和先生的情况,得到下面的情况: 
积 = 52, 和 = 17, m = 4, n = 13 
积 = 9604, 和 = 196, m = 98, n = 98 

如果规定了m不等于n,则最后的解答就是 
m=4 , n=13 

很严谨的逻辑,精准的推理,让我想起黑书上的一道递归题:

阅读(648) | 评论(0) | 转发(0) |
0

上一篇:笔记本做wifi热点

下一篇:一道百度面试题

给主人留下些什么吧!~~