#include <stdio.h>
//a{n} = -6a{n-1} -9a{n-2}, a{1}=1, a{2}=2(再帰あり版)
int c=0;
int rec(int n){
c++;
if(n==1){
return 1;
}
else if(n==2){
return 2;
}
else{
return -6*rec(n-1)-9*rec(n-2);
}
}
int main(void) {
int n = 4;
printf("数列a%dの値は%d\n", n
, rec
(n
)); printf("recが呼び出された回数は%d\n",c
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Ci8vYXtufSA9IC02YXtuLTF9IC05YXtuLTJ9LCBhezF9PTEsIGF7Mn09Mijlho3luLDjgYLjgorniYgpCmludCBjPTA7CmludCByZWMoaW50IG4pewoJYysrOwoJaWYobj09MSl7CgkJcmV0dXJuIDE7Cgl9CgkKCWVsc2UgaWYobj09Mil7CgkJcmV0dXJuIDI7Cgl9CgkKCWVsc2V7CgkJcmV0dXJuIC02KnJlYyhuLTEpLTkqcmVjKG4tMik7Cgl9Cn0KCmludCBtYWluKHZvaWQpIHsKICAgIGludCBuID0gNDsKICAgIHByaW50Zigi5pWw5YiXYSVk44Gu5YCk44GvJWRcbiIsIG4sIHJlYyhuKSk7CiAgICBwcmludGYoInJlY+OBjOWRvOOBs+WHuuOBleOCjOOBn+WbnuaVsOOBryVkXG4iLGMpOwoJcmV0dXJuIDA7Cn0KCg==