#GL0000371. Mocha và những ngôi sao (Mocha and Stars)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mocha và những ngôi sao (Mocha and Stars)
Mocha and Stars
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are stars. Choose an integer brightness for the -th star from the interval . A selection is valid if all of the following hold:
- for every ;
- ;
- .
Two selections differ if some position has different brightness. Count all valid selections modulo .
Every is positive. If , the answer is zero.
Input
The first line contains . Each of the following lines contains .
Output
Output the number of valid tuples modulo .
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Example 1
Input
2 4
1 3
1 2
Output
4
Explanation
The valid tuples are , , , and . Tuple has GCD ; tuple has sum .
Example 2
Input
5 10
1 10
1 10
1 10
1 10
1 10
Output
251
Explanation
Start with in all five positions. Distributing up to five further units gives choices. If a choice has GCD greater than , each value is at least . Under the sum bound of , the only such choice is . Removing it leaves .