F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Expected Remainder

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 55    Accepted Submission(s): 14


Problem Description
在$[a,b]$中均匀随机选取一个实数$x$,在$[c,d]$中均匀随机选取一个实数$y$,请问$x\ mod\ y$的期望,也就是$x-\lfloor \frac{x}{y} \rfloor y$是多少。

容易证明当$a,b,c,d$是正整数且区间长度大于$0$时,答案是有理数$r$,那么请问$r$模$10^9+7$的值是多少。

对于一个有理数$r = n/m$,其中$n, m$互质,那么我们定义它模素数$p$的值为,如果$p | m$,那么为$0$,否则为 $l (0 \leq l \le p)$,满足$ml \equiv n\ (mod\ p)$。
 

Input
第一行一个正整数$T(T\leq 2\times 10^5)$表示数据组数。

对于每组数据,第一行四个正整数$a, b, c, d( 1\leq a < b \leq 10^6, 1\leq c < d \leq 10^6)$。
 

Output
对于每组数据,输出一行一个整数表示答案。
 

Sample Input
2 1 2 1 2 1 2 2 4
 

Sample Output
833333340 500000005
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-02 13:38:09, Gzip enabled