#include <stdio.h>
//練習問題G
int func(int n){
int a, b=2, c=1;
int i;
if(n==1){
return 1;
}
else if(n==2){
return 2;
}
else{
for(i=3;i<=n;i++){
a=-2*b+2*c;
c=b;
b=a;
}
}
return a;
}
int main(void) {
int n = 3;
printf("数列anについて, n=%dのときの値は%d\n", n
, func
(n
)); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Ci8v57e057+S5ZWP6aGMRwoKaW50IGZ1bmMoaW50IG4pewogICAgaW50IGEsIGI9MiwgYz0xOwogICAgaW50IGk7CiAgICBpZihuPT0xKXsKICAgIAlyZXR1cm4gMTsKICAgIH0KICAgIGVsc2UgaWYobj09Mil7CiAgICAJcmV0dXJuIDI7CiAgICB9CiAgICBlbHNlewogICAgCWZvcihpPTM7aTw9bjtpKyspewogICAgCQlhPS0yKmIrMipjOwogICAgCQljPWI7CiAgICAJCWI9YTsKICAgIAl9CiAgICB9CQogICAgcmV0dXJuIGE7Cgp9CmludCBtYWluKHZvaWQpIHsKCWludCBuID0gMzsKICAgIHByaW50Zigi5pWw5YiXYW7jgavjgaTjgYTjgaYsIG49JWTjga7jgajjgY3jga7lgKTjga8lZFxuIiwgbiwgZnVuYyhuKSk7CglyZXR1cm4gMDsKfQo=