Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
526 B
3
Indexable
Never
#include <stdio.h>
int a,b,c,d,n;
int f(int);
int g(int);
int main(){
    scanf("%d%d%d%d%d", &a, &b, &c, &d, &n);
    printf("%d %d\n", f(n), g(n));
}

int f(int cnt){
    if(cnt == 0) return a;
    else if(cnt == 1) return b;
    else if(cnt % 2 == 0) return f(cnt - 1) + g(cnt / 2);
    else return f(cnt - 1) + g(cnt - 2);
}

int g(int cnt){
    if(cnt == 0) return c;
    else if(cnt == 1) return d;
    else if(cnt % 3 == 0) return g(cnt - 1) + f(cnt / 3);
    else return g(cnt - 1) + f(cnt - 2);
}