#P3455. [POI 2007] ZAP-Queries

    ID: 2510 远端评测题 1500ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2007POI最大公约数,gcd莫比乌斯反演

[POI 2007] ZAP-Queries

Description

A cryptographer is trying to break a cipher called BSA.

He found that while breaking a message, he also needs to answer the following question:

Given a,b,da,b,d, count the number of pairs (x,y)(x,y) such that 1xa1 \leq x \leq a, 1yb1 \leq y \leq b, and gcd(x,y)=d\gcd(x,y)=d.

Because there are so many problems to solve, he asks for your help.

Input Format

The first line contains an integer nn, the number of queries.

Each of the next nn lines contains three integers a,b,da,b,d.

Output Format

For each query, output a single integer representing the answer.

2
4 5 2
6 4 3
3
2

Hint

Constraints

For all testdata, it is guaranteed that 1n5×1041 \leq n \leq 5 \times 10^4, 1da,b5×1041 \leq d \leq a,b \leq 5 \times 10^4.

Translated by ChatGPT 5