#GL0000296. Bài toán đếm khác nhau (Yet Another Counting Problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bài toán đếm khác nhau (Yet Another Counting Problem)
Yet Another Counting Problem
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given two positive integers and independent queries. Each query specifies an inclusive integer interval .
For an integer , consider the two nested remainders taken in opposite orders:
These expressions may differ. For each query, count the integers satisfying and . The parameters and stay unchanged for every query.
Input
The first line contains . Each of the following lines contains , the inclusive endpoints of one query.
Output
Print one line of exactly space-separated integers in query order. The -th number is the required count for query .
Subtasks
- Subtask 1 (20 points): ; ; ; for each .
- Subtask 2 (30 points): ; ; ; for each .
- Subtask 3 (50 points): ; ; ; for each .
Examples
Examples 1
Input
4 6 5
1 1
1 3
1 5
1 7
1 9
Output
0 0 0 2 4
Explanation
For , the integers satisfy the inequality, whereas through do not. The five query answers are .
Examples 2
Input
7 10 2
7 8
100 200
Output
0 91
Explanation
The interval contributes zero. The period is , and positions with period remainder at least qualify. Counting within gives .