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 k and x, for all passwords. Each password is a string s of length n satisfying these properties.
- s uses only the first k lowercase letters of the English alphabet.
- For every pair of indices 1≤i<j≤n such that (j−i) is divisible by x, the letters si and sj are different.
Find the smallest integer n such that no valid string of length n exists.
Blackslex 正在为 Gean Dev 设计一个登录系统,他发现大多数用户使用弱密码。
为解决此问题,他针对所有密码提出了以下依赖于两个变量 k 和 x 的条件。每个密码是一个长度为 n 的字符串 s,且满足如下性质:
- s 仅使用英文字母表的前 k 个小写字母;
- 对于任意一对下标 1≤i<j≤n,若 (j−i) 能被 x 整除,则字符 si 与 sj 必须不同。
求使得不存在合法字符串的最小整数 n。
输入格式
The first line contains a single integer t (1≤t≤500) — the number of test cases.
The first and only line of each test case contains two integers k and x (1≤k≤26, 1≤x≤15).
第一行包含一个整数 t(1≤t≤500)—— 表示测试用例的数量。
每个测试用例仅有一行,包含两个整数 k 和 x(1≤k≤26,1≤x≤15)。
输出格式
For each test case, output the minimal n.
对于每个测试用例,输出最小的 n。
输入输出样例
输入#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=3. For n=2, one such valid example is ab. Note that the only pair (i,j) that (j−i) is divisible by x=1 and 1≤i<j≤n for n=2 is (1,2).
For the second test case, there are no valid strings of length n=7. For n=6, one such valid example is aabccb. Note that all pairs (i,j) that (j−i) is divisible by x=2 and 1≤i<j≤n for n=6 include (1,3), (1,5), (2,4), (2,6), (3,5), and (4,6).
For the third test case, there are no valid strings of length n=6. For n=5, one such valid example is aaaaa. Note that there are no pairs (i,j) that (j−i) is divisible by x=5 and 1≤i<j≤n for n=5.
对于第一个测试用例,不存在长度为 n=3 的合法字符串。对于 n=2,一个合法的例子是 ab。注意:当 n=2 时,满足 (j−i) 被 x=1 整除且 1≤i<j≤n 的唯一数对 (i,j) 是 (1,2)。
对于第二个测试用例,不存在长度为 n=7 的合法字符串。对于 n=6,一个合法的例子是 aabccb。注意:当 n=6 时,所有满足 (j−i) 被 x=2 整除且 1≤i<j≤n 的数对 (i,j) 包括 (1,3)、(1,5)、(2,4)、(2,6)、(3,5) 和 (4,6)。
对于第三个测试用例,不存在长度为 n=6 的合法字符串。对于 n=5,一个合法的例子是 aaaaa。注意:当 n=5 时,不存在满足 (j−i) 被 x=5 整除且 1≤i<j≤n 的数对 (i,j)。
输入解题思路,AI测评打分。不知道怎么写?