猴子吃桃问题
另一种算法:
假定最后一个猴子拿到的桃子是last,然后向前倒推,看是否满足条件
public class Monkey {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int total ;
int i;
for (int last =1;last <1000;last++)
{
total = (last*5)+1;
for ( i= 0; i < 4; i++){
if (total%4!=0) break;
total = total + total/4 +1;
}
if (i==4) {
System.out.println("Total number is "+total);
break;
}
}
}
}