第 n 天早上剩 x_n,前一天 x_{n-1} = 2*(x_n + 1)。
第 10 天 x_{10} = 1。
int peaches(int days) {
int x = 1;
for (int d = days; d > 1; d--)
x = 2 * (x + 1);
return x;
}
// 10 天 -> 1534
int peaches_rec(int day, int curr) {
if (day == 1) return curr;
return peaches_rec(day - 1, 2 * (curr + 1));
}
// 呼叫: peaches_rec(10, 1)
int peaches_general(int total_days, int last_day_remain) {
int x = last_day_remain;
for (int d = total_days; d > 1; d--)
x = 2 * (x + 1);
return x;
}