#P2522. [HAOI2011] Problem b

    ID: 1537 远端评测题 2500ms 250MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2011河南各省省选最大公约数,gcd莫比乌斯反演容斥

[HAOI2011] Problem b

Description

For each of the given nn queries, count the number of pairs (x,y)(x,y) such that axba \le x \le b, cydc \le y \le d, and gcd(x,y)=k\gcd(x,y) = k. The function gcd(x,y)\gcd(x,y) denotes the greatest common divisor of xx and yy.

Input Format

The first line contains an integer nn. Each of the next nn lines contains five integers, denoting a,b,c,d,ka, b, c, d, k.

Output Format

Output nn lines, each containing one integer representing the number of pairs (x,y)(x,y) that satisfy the conditions.

2
2 5 1 5 1
1 5 1 5 2
14
3

Hint

Constraints: For 100%100\% of the testdata, the following holds: 1n,k5×1041 \le n,k \le 5 \times 10^4, 1ab5×1041 \le a \le b \le 5 \times 10^4, 1cd5×1041 \le c \le d \le 5 \times 10^4.

Translated by ChatGPT 5