시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.4 초 1024 MB409616.667%

문제

Today is the sequence day! The math teacher wrote some sequences on the whiteboard, each having N different numbers, all from 1 to N, and told the students that these sequences had some special property. After some careful consideration, one of the students, Deni, guessed the correct property. All the sequences on the whiteboard had at least one pair of adjacent numbers in the form (x, x + 1). Deni was so happy that she called this type of sequence pretty. For example, for N = 4 the sequences: 3, 1, 2, 4 and 2, 3, 4, 1 are pretty but the sequences 2, 4, 1, 3 and 4, 3, 2, 1 aren’t. After that, the math teacher gave Deni a harder question. She was asked to calculate the number of all possible pretty sequences with N different numbers, all from 1 to N. This was so hard that Deni couldn’t find an answer during the whole class. You are a friend of Deni and want to help her.

Write the program, which for a given N has to tell Deni the number of pretty sequences. This number can be rather large, so you have to calculate it modulo M.

입력

From the first line of the standard input, read two integers N and M – the length of the sequences on the whiteboard and the module, used for the calculation.

출력

On one line of the standard output, the program has to write one integer – the number of pretty sequences with N different numbers, all from 1 to N, modulo M.

제한

  • 1 ≤ N ≤ 1018
  • 2 ≤ M ≤ 107

서브태스크

번호배점제한
19

N ≤ 10

214

N ≤ 15

311

N ≤ 20

443

N ≤ 106

523

N ≤ 1018

예제 입력 1

4 42

예제 출력 1

13

The pretty sequences with 4 different numbers, all from 1 to 4, are:

1 2 3 4     3 1 2 4
1 2 4 3     3 4 1 2
1 3 4 2     3 4 2 1
1 4 2 3     4 1 2 3
2 1 3 4     4 2 3 1
2 3 1 4     4 3 1 2
2 3 4 1

예제 입력 2

2000 10009

예제 출력 2

1295

채점 및 기타 정보

  • 예제는 채점하지 않는다.