列表找
#include <stdio.h>
#include <stdlib.h>
int fq(int x, int sorx) //sorx==1 a
{
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;
}