#include <stdio.h>
//a{n} = -6a{n-1} -9a{n-2}, a{1}=1, a{2}=2(再帰あり版)
int c;
int rec(int n){
if(n==1){
c++;
return 1;
}
else if(n==2){
c++;
return 2;
}
else{
c++;
return -6*rec(n-1)-9*rec(n-2);
}
}
int main(void) {
int n = 5;
printf("数列a%dの値は%d\n", n
, rec
(n
)); printf("このときrecの呼び出し回数は%d",c
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Ci8vYXtufSA9IC02YXtuLTF9IC05YXtuLTJ9LCBhezF9PTEsIGF7Mn09Mijlho3luLDjgYLjgorniYgpCmludCBjOwppbnQgcmVjKGludCBuKXsKICBpZihuPT0xKXsKICAgIGMrKzsKCXJldHVybiAxOwogIH0KICBlbHNlIGlmKG49PTIpewogICAgYysrOwoJcmV0dXJuIDI7CiAgfQogIGVsc2V7CiAgICBjKys7CglyZXR1cm4gLTYqcmVjKG4tMSktOSpyZWMobi0yKTsKICB9CgoKfQoKaW50IG1haW4odm9pZCkgewogICAgaW50IG4gPSA1OwogICAgcHJpbnRmKCLmlbDliJdhJWTjga7lgKTjga8lZFxuIiwgbiwgcmVjKG4pKTsKICAgIHByaW50Zigi44GT44Gu44Go44GNcmVj44Gu5ZG844Gz5Ye644GX5Zue5pWw44GvJWQiLGMpOwoJcmV0dXJuIDA7Cn0KCg==