解决这个算法 [英] Solve this algorithm

查看:79
本文介绍了解决这个算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ghost and Shadow正在玩游戏。 Shadow给Ghost一个数字n,Ghost必须给Shadow一个cookie。 cookie的数量计算为n的最大除数(当然不等于n)。例如,如果n = 6,Ghost必须提供3个cookie,而对于n = 25,他需要给5,如果n = 2,他只需要提供1个cookie。



由于Ghost非常聪明,他想愚弄Shadow。他引入了一条规则说,他可以将n分成几个n1 + n2 + ... + nk = n(这里k是任意的,k = 1也是可能的),他将根据这些分割部分给出cookie。 ni 2,对于我从1到k的所有i。



帮助Ghost计算他必须提供多少个cookie。



我尝试了什么:



我的代码用于分割数字分为两部分

Ghost and Shadow were playing a game. Shadow gives Ghost a number n and Ghost has to give cookies to Shadow. The number of cookies is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 the Ghost has to give 3 cookies, while for n = 25 he needs to give 5 and if n = 2 he only needs to give 1 cookie.

As Ghost is very smart he wants to fool Shadow. He introduces a rule saying, that he can break n into several n1 + n2 + ... + nk = n (here k is arbitrary and k = 1 is also possible) and he will give the cookies according to those split parts. ni 2, for all i from 1 to k.

Help Ghost calculate how many cookies he has to give.

What I have tried:

My code is working for splitting number in two parts

推荐答案

我们不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


这篇关于解决这个算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆