PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CT0000056. Dãy bậc thang (Staircase Sequence)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Đang đọc
Dãy bậc thang (Staircase Sequence)
Staircase Sequence
Version: Phuoc Hung OJ Extended
Problem Statement
A positive integer sequence is defined by
For a positive integer , define
Since can be very large, may exceed ordinary integer types. Compute the remainder of when divided by the positive integer .
Input
The first line contains the positive integer .
The second line contains the positive integer .
Output
Print one integer: .
Subtasks
- Subtask 1 (30%): , .
- Subtask 2 (30%): , .
- Subtask 3 (40%): , .
Examples
Example 1
Input
3
100
Output
20
Explanation
The first three terms are , so .
Example 2
Input
10
97
Output
52
Explanation
The sum of the first ten terms is . Since , the remainder is .
Example 3
Input
5
7
Output
0
Explanation
The first five terms are ; their sum is , which is divisible by .
Liên quan
Trong các cuộc thi sau: