QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#12689. Queries

統計

Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He has already found out that whilst deciphering a message he will have to answer multiple queries of the form “for given integers $a$, $b$ and $d$, find the number of integer pairs $(x, y)$ satisfying the following conditions:

  • $1 ≤ x ≤ a$,
  • $1 ≤ y ≤ b$,
  • $\gcd(x,y) = d$, where $\gcd(x,y)$ is the greatest common divisor of $x$ and $y$.”

Byteasar would like to automate his work, so he has asked for your help.

Task

Write a programme which:

  • reads from the standard input a list of queries, which the Byteasar has to give answer to,
  • calculates answers to the queries,
  • writes the outcome to the standard output.

Input

The first line of the standard input contains one integer $n$ ($1 ≤ n ≤ 50\,000$), denoting the number of queries. The following $n$ lines contain three integers each: $a$, $b$ and $d$ ($1 ≤ d ≤ a,b ≤ 50\,000$), separated by single spaces. Each triplet denotes a single query.

Output

Your programme should write $n$ lines to the standard output. The $i$'th line should contain a single integer: the answer to the $i$'th query from the standard input.

Example

Input

2
4 5 2
6 4 3

Output

3
2

The pairs satisfying the first query are: (2,2), (2,4) and (4,2). The pairs satisfying the second query are: (6,3) and (3,3).

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.