PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000372. Tổng bội chung nhỏ nhất – bản khó (LCM Sum (Hard Version))

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng bội chung nhỏ nhất – bản khó (LCM Sum (Hard Version))

LCM Sum (Hard Version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given qq independent range queries. Each query specifies l,rl,r. Count the strictly increasing triples (i,j,k)(i,j,k) satisfying

$$l\le i<j<k\le r,\qquad \operatorname{lcm}(i,j,k)\ge i+j+k.$$

Here, lcm⁡\operatorname{lcm} is the least common multiple of three integers. The ordering i<j<ki<j<k ensures that every distinct triple is counted exactly once.

An answer may exceed the 32-bit integer range; use 64-bit arithmetic. Queries do not modify any data; output their answers in input order.

Input

The first line contains qq. Each of the next qq lines contains l,rl,r. A single input file contains one batch of queries, allowing offline processing.

Output

Print qq lines, the number of valid triples for each query, in order.

Subtasks

  • Subtask 1 (20 points): 1≤q≤201\le q\le20; 1≤l<l+2≤r≤3001\le l<l+2\le r\le300.
  • Subtask 2 (30 points): 1≤q≤1 0001\le q\le1\,000; 1≤l<l+2≤r≤20 0001\le l<l+2\le r\le20\,000.
  • Subtask 3 (50 points): 1≤q≤100 0001\le q\le100\,000; 1≤l<l+2≤r≤200 0001\le l<l+2\le r\le200\,000.

Examples

Example 1

Input

5
1 4
3 5
8 86
68 86
6 86868

Output

3
1
78975
969
109229059713337

Explanation

For [1,4][1,4], the four triples are (1,2,3)(1,2,3), (1,2,4)(1,2,4), (1,3,4)(1,3,4), and (2,3,4)(2,3,4). Only (1,2,4)(1,2,4) is invalid, since its LCM is 4<74<7. For [3,5][3,5], the only triple is (3,4,5)(3,4,5), and its LCM is 60≥1260\ge12.