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

问题描述

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

推荐答案


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

07-09 18:15