// Question: The Monkey eats peach. The monkey picks up several peaches on the first day and eats half of them immediately.
// In the morning of the next day, I ate half of the remaining peaches and one more peach.
// In the future, I eat the remaining half of the previous day every morning. When you want to eat again in the morning of the seventh day, there is only one peach left.
// Calculate the total number on the first day.
Package WZS. arithmetics; // question: a monkey eats peaches. The monkey picks up a few peaches on the first day and eats half of them instantly, I have eaten another one. // I have eaten the remaining peaches in half the next morning, and I have eaten another one. // then I have eaten the remaining half of the previous day every morning. When you want to eat again in the morning of the seventh day, there is only one peach left. // Calculate the total number on the first day. Public class test_wzs16 {public static void main (string [] ARGs) {system. out. println (Total (1); system. out. println (total (2); system. out. println (total (3); system. out. println (total (4); system. out. println (total (5); system. out. println (total (6); system. out. println (total (7); system. out. println (total (8); system. out. println (total (9); system. out. println (total (10);}/*** Number of peaches per day * @ Param day * @ return number of peaches per day */static int total (INT Day) {If (Day = 10) {return 1;} else {return (total (day + 1) + 1) * 2 ;}}}
Output result:
15347663821909446221041