内容中心

2026年比较好的昆明个人所得税税务筹划推荐榜单公司-云南慧力量企业管理有限公司

To solve this problem, we need to find the maximum value of (A \mod B) where (A) and (B) are integers in the range ([L, R]) and (A > B).

Approach

The key insight to solve this problem efficiently is to recognize that for a given (B), the maximum possible remainder when dividing any number by (B) is (B-1) (since the remainder must be less than (B)). This remainder is achievable if there exists an (A) in the range ([B+1, R]) such that (A = 2B -1) (since (2B-1 \mod B = B-1)).

If (2B -1 > R), then the maximum remainder for (B) is (R \mod B) (since (R) is the largest number in the range, its remainder when divided by (B) will be the highest possible for any (A \leq R)).

Solution Code

L, R = map(int, input().split())

if L == R:
    print(0)
else:
    max_mod = 0
    for B in range(L, R):
        if 2 * B - 1 <= R:
            current = B - 1
        else:
            current = R % B
        if current > max_mod:
            max_mod = current
    print(max_mod)

Explanation

  1. Edge Case Handling: If (L == R), there are no valid pairs where (A > B), so the result is 0.
  2. Iterate Over Possible Values of (B): For each (B) from (L) to (R-1):
    • Check if (2B -1 \leq R). If yes, the maximum remainder for this (B) is (B-1).
    • If not, the maximum remainder is (R \mod B).
  3. Track Maximum Remainder: Keep updating the maximum remainder found across all values of (B).

This approach efficiently computes the result with a time complexity of (O(R-L)), which is feasible for the given constraints (up to (10^6)). This ensures the solution is both optimal and easy to understand.

Example: For (L = 3) and (R =7):

  • (B=3): (2*3-1=5 \leq 7), remainder is (2).
  • (B=4): (2*4-1=7 \leq7), remainder is (3).
  • (B=5): (2*5-1=9>7), remainder is (7\%5=2).
  • (B=6): (2*6-1=11>7), remainder is (7\%6=1).

The maximum remainder is (3), which is the correct result.

This solution effectively handles all cases and provides the optimal result.

云南慧力量企业管理有限公司

云南慧力量企业管理有限公司



(免责声明:本文为本网站出于传播商业信息之目的进行转载发布,不代表本网站的观点及立场。本文所涉文、图、音视频等资料的一切权利和法律责任归材料提供方所有和承担。本网站对此资讯文字、图片等所有信息的真实性不作任何保证或承诺,亦不构成任何购买、投资等建议,据此操作者风险自担。) 本文为转载内容,授权事宜请联系原著作权人,如有侵权,请联系本网进行删除。

在线客服

在线留言
您好,很高兴为您服务,可以留下您的电话或微信吗?