某数列计算规则如图所示,已知a0 = 0,要求编写int fun(int n)函数来计算第n项的值an。
int f(int n) { if(n == 0) return 0; if(n&1) return 2 * f(n-1) + 1; return 2 * f(n-1) - 1; }