CF1562A.The Miracle and the Sleeper

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two integers ll and rr, l≤rl\le r. Find the largest possible value of a mod ba \bmod b over all pairs (a,b)(a, b) of integers for which r≥a≥b≥lr\ge a \ge b \ge l.

As a reminder, a mod ba \bmod b is a remainder we get when dividing aa by bb. For example, 26 mod 8=226 \bmod 8 = 2.

给你两个整数 ll 和 rr,满足 l≤rl \le r。在所有满足 r≥a≥b≥lr \ge a \ge b \ge l 的整数对 (a,b)(a, b) 中,求 a mod ba \bmod b 的最大可能值。

需要提醒的是,a mod ba \bmod b 表示将 aa 除以 bb 所得的余数。例如,26 mod 8=226 \bmod 8 = 2。

输入格式

Each test contains multiple test cases.

The first line contains one positive integer tt (1≤t≤104)(1\le t\le 10^4), denoting the number of test cases. Description of the test cases follows.

The only line of each test case contains two integers ll, rr (1≤l≤r≤1091\le l \le r \le 10^9).

每个测试包含多个测试用例。

第一行包含一个正整数 tt(1≤t≤1041\le t\le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含两个整数 ll 和 rr(1≤l≤r≤1091\le l \le r \le 10^9)。

输出格式

For every test case, output the largest possible value of a mod ba \bmod b over all pairs (a,b)(a, b) of integers for which r≥a≥b≥lr\ge a \ge b \ge l.

对于每个测试用例,输出所有满足 r≥a≥b≥lr\ge a \ge b \ge l 的整数对 (a,b)(a, b) 中 a mod ba \bmod b 的最大可能值。

输入输出样例

  • 输入#1

    4
    1 1
    999999999 1000000000
    8 26
    1 999999999

    输出#1

    0
    1
    12
    499999999

说明/提示

In the first test case, the only allowed pair is (a,b)=(1,1)(a, b) = (1, 1), for which a mod b=1 mod 1=0a \bmod b = 1 \bmod 1 = 0.

In the second test case, the optimal choice is pair (a,b)=(1000000000,999999999)(a, b) = (1000000000, 999999999), for which a mod b=1a \bmod b = 1.

在第一个测试用例中,唯一允许的数对是 (a,b)=(1,1)(a, b) = (1, 1),此时 a mod b=1 mod 1=0a \bmod b = 1 \bmod 1 = 0。

在第二个测试用例中,最优选择是数对 (a,b)=(1000000000,999999999)(a, b) = (1000000000, 999999999),此时 a mod b=1a \bmod b = 1。

输入解题思路,AI测评打分。不知道怎么写?

首页