1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include <stdio.h> #include <stdlib.h>
int fq(int x, int sorx) { if (x == 1 || x == 2 || (sorx && x == 4) || (!sorx && x == 3)) return 0; if ((x == 3 && sorx) || (x == 4 && !sorx)) return 1; int *a = (int *)malloc(sizeof(int) * x); int *res = (int *)malloc(sizeof(int) * x); a[0] = a[1] = res[0] = 1; res[1] = 2; int j = 2, i; i = x - 5 + (sorx ? 0 : 1); while (j <= i) { a[j] = a[j - 1] + a[j - 2]; res[j] = a[j] + res[j - 1]; j += 1; } return res[i]; }
int main() { int a, n, m, x; scanf("%d%d%d%d", &a, &n, &m, &x); if (x == 1 || x == 2) { printf("%d", a); return 0; } if (x == 3) { printf("%d", 2 * a); return 0; } int b = (m - (2 + fq(n - 1, 1)) * a) / fq(n - 1, 0); printf("%d", (2 + fq(x, 1)) * a + fq(x, 0) * b); return 0; }
|