说实话,我怀疑这道题目是没有答案的,但是我还不能证明。
package test;
public class Peach {
private long copyCount = 5;
private long mokeyCount = 5;
public Peach() {
}
public Peach(long copyCount, long mokeyCount) {
this.copyCount = copyCount;
this.mokeyCount = mokeyCount;
}
/**
* leftCount 最后海滩上还剩下的桃子数目
* @param leftCount
* @return
*/
private long divideOnce(long leftCount)
{
return leftCount / 4 * copyCount + 1;
}
/**
* 获取桃子的总数
* @return
*/
public long getTotal()
{
long ret = 4;
int k = 1, start = 2;
//如果输入的参数是0,或者不是4的倍数,说明输入参数无效
while (true) {
if (k == mokeyCount) {
break;
}
if (ret % 4 == 0) {
ret = divideOnce(ret);
k++;
} else {
ret = 4 * start;
start++;
k = 1;
}
}
return ret;
}
public static void main(String[] args) {
System.out.println(new Peach().getTotal());
//124(496) 99(396) 79(316) 63(252)
}
}
我写了一个算法,但是结果似乎有问题,不懂了,大家讨论讨论