猴子分桃问题海滩上有一堆桃子,五只猴子来分.第一只猴子把这堆桃子凭据分为五份,多了一个,这只猴子把多的一个扔入海中,拿走
1个回答

试试这个:

public static void main(String[] args){

int peaches;

for(int i=1;;i++){

if(i%5==1){

peaches=(i-1)/5*4;

if(peaches%5==1){

peaches=(peaches-1)/5*4;

if(peaches%5==1){

peaches=(peaches-1)/5*4;

if(peaches%5==1){

peaches=(peaches-1)/5*4;

if(peaches%5==1) System.out.println(i);

}

}

}

}

}

}

相关问题