Title Description Description
The train departs from the starting point (called the 1th Station), the number of passengers arriving at the start of the station is a, then to the 2nd stop, and at the 2nd stop, the number of people on and off the bus is the same, so the number of passengers on the 2nd station (i.e. before arriving at the 3rd station) remains a. From the 3rd station (including the 3rd station), the number of people have a certain rule: the number of passengers are the first two stations on the number of passengers, and the number of alight is equal to the number of passengers on the last station, until the end of the previous station (section N-1 station), are satisfied with this law. The conditions are as follows: There are n stations, the number of passengers on the bus is a, and the number of the last stop is M (all get off). How many people are there on the bus from X station? If no solution output "no answer." (All data is within the Longint range)
Enter a description
Input Description
A,n,m and X
Output description
Output Description
The number of people on the bus when X station departs
Sample input
Sample Input
1 6 7 3
Sample output
Sample Output
2
/* Number of stations is b[i-1]*a+c[i-1]*k that is m-b[i-1]*a if can be c[i-1] divisible so the number of X station is b[x]*a+c[x]* (m-b[n-1]*a)/(c[n-1]) Otherwise output "No answer." * /#include <cstdio>using namespace Std;int b[1001]={0,1,1,2},c[1001];int main () {int a,n,m,x,i;scanf ("%d%d%d%d", &A,&N,&M,&X); if (x==1| | x==2) {printf ("%d", a); return 0;} for (i=4;i<=n;i++) {b[i]=b[i-1]+b[i-2]-1;c[i]=c[i-1]+c[i-2]+1;printf ("%d%d\n", B[i],c[i]);} if ((m-b[n-1]*a)% (c[n-1]) ==0) printf ("%d", b[x]*a+c[x]* (m-b[n-1]*a)/(C[n-1])), Else printf ("No answer."); return 0;}
Code 2287 train Station