目录
LCM Sum (hard version)
This version of the problem differs from the previous one only in the constraint on tt. You can make hacks only if both versions of the problem are solved.
You are given two positive integers ll and rr.
Count the number of distinct triplets of integers (i,j,k)(i,j,k) such that l≤i Here lcm(i,j,k)lcm(i,j,k) denotes the least common multiple (LCM) of integers ii, jj, and kk. Input Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1051≤t≤105). Description of the test cases follows. The only line for each test case contains two integers ll and rr (1≤l≤r≤2⋅1051≤l≤r≤2⋅105, l+2≤rl+2≤r). Output For each test case print one integer — the number of suitable triplets. Example input Copy 5 1 4 3 5 8 86 68 86 6 86868 output Copy Note In the first test case, there are 33 suitable triplets: In the second test case, there is 11 suitable triplet: 正难则反 1,讨论总的情况:(r-l+1)*(r-l-1)/6 2,讨论lcm的情况:lcm(i,j,k)lcm<3*k,=>lcm为k或者2*k 3,讨论i,j的情况: 当lcm为2*k时: 1)k/2 2)2*kkk/32 当lcm为k时: i 4,树状数组记载每个数作为i的可行情况数3
1
78975
969
109229059713337
思路:
代码: