## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] LCM Sum (hard version) Codeforces Solution

E2. LCM Sum (hard version)
time limit per test
3.5 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

This version of the problem differs from the previous one only in the constraint on

$t$. You can make hacks only if both versions of the problem are solved.

You are given two positive integers $l$ and $r$.

Count the number of distinct triplets of integers $\left(i,j,k\right)$ such that $l\le i and $\mathrm{lcm}\left(i,j,k\right)\ge i+j+k$.

Solution Click Below:-  👉
👇👇👇👇👇

Here $\mathrm{lcm}\left(i,j,k\right)$ denotes the least common multiple (LCM) of integers $i$$j$, and $k$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($\mathbf{1}\le \mathbf{t}\le {\mathbf{10}}^{\mathbf{5}}$). Description of the test cases follows.

The only line for each test case contains two integers $l$ and $r$ ($1\le l\le r\le 2\cdot {10}^{5}$$l+2\le r$).

Output

For each test case print one integer — the number of suitable triplets.