G. 约数最多的数 / Has Many Divisors

    传统题 2000ms 256MiB

约数最多的数 / Has Many Divisors

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Statement

You are given integers NN and DD, each at least 22.

Among the positive integers at most NN that are not multiples of DD, find one with the maximum number of positive divisors. If there are multiple such positive integers, output any one of them.

You are given TT test cases; solve each of them.

Constraints

  • 1≤T≤101 \leq T \leq 10
  • 2≤D≤N≤10182 \leq D \leq N \leq 10^{18}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

  • TT
  • case1\text{case}_1
  • case2\text{case}_2
  • ⋮\vdots
  • caseT\text{case}_T

Here, casei\text{case}_i represents the ii-th test case, and is given in the following format:

  • NN DD

Output

Output TT lines. The ii-th line should contain the answer for the ii-th test case.

4
10 2
17 4
2026 919
1000000000000 48
9
15
1680
843291048600

The positive integers at most 1010 that are not multiples of 22 are the five integers 1,3,5,7,91, 3, 5, 7, 9, and the numbers of their positive divisors are 1,2,2,2,31, 2, 2, 2, 3, respectively. Therefore, output 99 for the first test case.

For the second test case, besides 1515 in the sample output, outputting any of 6,10,146, 10, 14 is also accepted.

ABC475 赛后模拟赛 ✅

未参加
状态
已结束
规则
IOI
题目
7
开始于
2026-9-12 21:40
结束于
2026-9-26 21:40
持续时间
336 小时
主持人
参赛人数
59