PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000008. Có bao nhiêu cách cộng (How Do You Add?)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Có bao nhiêu cách cộng (How Do You Add?)
How Do You Add?
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Given two positive integers and , consider all ordered -tuples of nonnegative integers satisfying
Two tuples are different if their values differ at any position. Count the valid tuples and print the result modulo .
Input
The input is one line containing two integers and .
Output
Print one integer: the number of valid ordered tuples modulo .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
20 2
Output
21
Explanation
For , choose from through , then . There are choices for , hence ordered pairs.