Benny and GCD
Practice
4 (7 votes)
Mathematics
Approved
Easy
Greatest common divisor
Problem
93% Success 4336 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Probably, you have already guessed that Benny doesn't like math at all. Especially, she is really bad at number theory.

Little Benny wants you to answer one single questions that disturbs her every night.

You will be given three integers: l, r, g. You have to output the number of pairs of integers x and y such that \(\gcd(x, y) = g\) and \(l \leq x, y \leq r\).

Note that pairs \((1, 2)\) and \((2, 1)\) are different.

Input format

The first line contains three integers l, r and g

Constraints

\(1 \leq l, r, g \leq 10^9\)

\(0 \leq r-l \leq 10^3 \cdot g\)

Output format

Output single integer: the answer to the problem.

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:20
2 votes
Tags:
EasyNumber Theory
Points:20
1 votes
Points:50
13 votes
Tags:
AlgorithmsApprovedHardOpenTrees