/* (Start of program header comment)
* Copyright and version Declaration section of the program
* Copyright (c) 2016, Guangzhou Science and Technology Trade Vocational College, Department of Information Engineering students
* All rights reserved.
* File name: Blue Bridge Cup title
* Author: Pengjunhau
* Completion Date: April 01, 2016
* Version number: 001
* Description part of task and solution method
* Description of the problem:
There are n-steps. Starting from the ground (level No. 0), the first successive upper steps, up to no more than the nth level
A certain position and then successive steps down the stairs until it returns to the ground. If only 1 or 2 levels are allowed to go up and down each step,
What is the possible number of scenarios for the upper and lower steps?
In particular, standing still at level 0 is a solution.
Data format:
The input line consists of two positive integers n and M.
Outputs an integer that indicates how many legal stair steps there are for an n-level step, and the answer to M-redundancy.
For example: Enter:
2 10007
The program should output
6
* Program output:
"Sample Description 1"
There are 6 kinds of scenarios (where + represents the upper step, which represents the next step):
(1) Do not move in situ
(2) +1-1
(3) +2-2
(4) +2-1-1
(5) +1 +1-2
(6) +1 +1-1-1
Again, for example, enter:
3 14
The program should output:
1
"Sample Description 2"
There are 15 kinds of programs, 14 after the surplus 1.
"Data Size"
For 30% of data,n<=10000;
For 100% of data, n<=10^17,m<=2*10^9.
* End of comment on the program head
*/
On the code:
Import Java.util.Scanner;
public class Test {
public static void Main (string[] args) {
Scanner input=new Scanner (system.in);
int N=input.nextint ();
int M=input.nextint ();
Int[] Walk=new int[n+1]; Number of methods to step up
walk[0]=1;walk[1]=2;
for (int i=2;i<n;i++) {
WALK[I]=WALK[I-1]+WALK[I-2];
}
int sum=1;//method of standing still
for (int i=0;i<n;i++) {
Sum+=walk[i]*walk[i];
}
System.out.println (sum%m);
}
}
Fifth session Blue Bridge Cup Java Group University campus selection true title _n step