A - LCMer
Practice
3.5 (11 votes)
Medium Hard
Problem
28% Success 59 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given T test cases. In each of them you are given four integers N, L, R and X. Your task is to count modulo 109+7 the number of sequences of integers A satisfying the following conditions:
1) A should contain exactly N elements.
2) L ≤ A1 ≤ A2 ≤ ... ≤ AN ≤ R
3) the least common multiple of all numbers in A should be divisible by X.

Input format

The first line contains one integer number T, denoting the number of test cases.

Each of the next T lines contains four integers N, L, R, X.

Output format

For each test case find the answer and print it modulo 109+7 in a separate line.

Constraints

1 ≤ T ≤ 100
1 ≤ N ≤ 100
1 ≤ L, R, X ≤ 109

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
20 votes
Tags:
Counting and ArrangementsDynamic ProgrammingAlgorithmsNumber theory
Points:50
Tags:
Medium-HardMedium-Hard
Points:50
3 votes
Tags:
Medium-Hard