CF2179A.Blackslex and Password

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Blackslex is designing a log-in system for Gean Dev and discovered that most users use weak passwords.

To resolve this issue, he posed the following conditions, dependent on two variables kk and xx, for all passwords. Each password is a string ss of length nn satisfying these properties.

  • ss uses only the first kk lowercase letters of the English alphabet.
  • For every pair of indices 1≤i<j≤n1 \le i \lt j \le n such that (j−i)(j-i) is divisible by xx, the letters sis_i and sjs_j are different.

Find the smallest integer nn such that no valid string of length nn exists.

Blackslex 正在为 Gean Dev 设计一个登录系统,他发现大多数用户使用弱密码。

为解决此问题,他针对所有密码提出了以下依赖于两个变量 kk 和 xx 的条件。每个密码是一个长度为 nn 的字符串 ss,且满足如下性质:

  • ss 仅使用英文字母表的前 kk 个小写字母;
  • 对于任意一对下标 1≤i<j≤n1 \le i \lt j \le n,若 (j−i)(j-i) 能被 xx 整除,则字符 sis_i 与 sjs_j 必须不同。

求使得不存在合法字符串的最小整数 nn。

输入格式

The first line contains a single integer tt (1≤t≤5001 \le t \le 500) — the number of test cases.

The first and only line of each test case contains two integers kk and xx (1≤k≤261 \le k \le 26, 1≤x≤151 \le x \le 15).

第一行包含一个整数 tt(1≤t≤5001 \le t \le 500)—— 表示测试用例的数量。

每个测试用例仅有一行,包含两个整数 kk 和 xx(1≤k≤261 \le k \le 26,1≤x≤151 \le x \le 15)。

输出格式

For each test case, output the minimal nn.

对于每个测试用例,输出最小的 nn。

输入输出样例

  • 输入#1

    3
    2 1
    3 2
    1 5

    输出#1

    3
    7
    6

说明/提示

For the first test case, there are no valid strings of length n=3n=3. For n=2n=2, one such valid example is ab. Note that the only pair (i,j)(i, j) that (j−i)(j-i) is divisible by x=1x=1 and 1≤i<j≤n1 \le i \lt j \le n for n=2n=2 is (1,2)(1, 2).

For the second test case, there are no valid strings of length n=7n=7. For n=6n=6, one such valid example is aabccb. Note that all pairs (i,j)(i, j) that (j−i)(j-i) is divisible by x=2x=2 and 1≤i<j≤n1 \le i \lt j \le n for n=6n=6 include (1,3)(1, 3), (1,5)(1, 5), (2,4)(2, 4), (2,6)(2, 6), (3,5)(3, 5), and (4,6)(4, 6).

For the third test case, there are no valid strings of length n=6n=6. For n=5n=5, one such valid example is aaaaa. Note that there are no pairs (i,j)(i, j) that (j−i)(j-i) is divisible by x=5x=5 and 1≤i<j≤n1 \le i \lt j \le n for n=5n=5.

对于第一个测试用例,不存在长度为 n=3n=3 的合法字符串。对于 n=2n=2,一个合法的例子是 ab。注意:当 n=2n=2 时,满足 (j−i)(j-i) 被 x=1x=1 整除且 1≤i<j≤n1 \le i \lt j \le n 的唯一数对 (i,j)(i, j) 是 (1,2)(1, 2)。

对于第二个测试用例,不存在长度为 n=7n=7 的合法字符串。对于 n=6n=6,一个合法的例子是 aabccb。注意:当 n=6n=6 时,所有满足 (j−i)(j-i) 被 x=2x=2 整除且 1≤i<j≤n1 \le i \lt j \le n 的数对 (i,j)(i, j) 包括 (1,3)(1, 3)、(1,5)(1, 5)、(2,4)(2, 4)、(2,6)(2, 6)、(3,5)(3, 5) 和 (4,6)(4, 6)。

对于第三个测试用例,不存在长度为 n=6n=6 的合法字符串。对于 n=5n=5,一个合法的例子是 aaaaa。注意:当 n=5n=5 时,不存在满足 (j−i)(j-i) 被 x=5x=5 整除且 1≤i<j≤n1 \le i \lt j \le n 的数对 (i,j)(i, j)。

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

首页