Package com. arithmetic; // question: there are a bunch of peaches on the beach, and five monkeys can score points. The first monkey divided the pile of peach creden into five portions, one more. The monkey threw the other one into the sea and took one. The second monkey divides the remaining peaches into five equal portions and adds one more portion. It also throws one more portion into the sea and takes one portion, // The third, fourth, and fifth monkeys do this. How many peaches are there on the beach? // Analysis: If you want to have at least one peach, the fifth monkey will take at least one peach, and there will be six peaches when dividing the peach. public class test_wzs30 {public static void main (string [] ARGs) {for (INT I = 5; I> 0; I --) {system. out. println ("no." + I + "monkeys have peaches:" + dividepeaches (I ));}} /*** peach ** @ Param Number * @ return */static int dividepeaches (INT number) {If (number = 5) {return 6 ;} else {return dividepeaches (number + 1) * 5 + 1 ;}}}
Output result:
5th monkeys have peaches: 4th monkeys have peaches: 31 3rd monkeys have peaches: 156 2nd monkeys have peaches: 781 1st monkeys have peaches: 3906 monkeys have peaches: