350 字
2 分钟
Blackslex-and-Password
题面
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 and , for all passwords. Each password is a string of length satisfying these properties.
- uses only the first lowercase letters of the English alphabet.
- For every pair of indices such that is divisible by , the letters and are different.
Find the smallest integer such that no valid string of length exists.
Input
The first line contains a single integer () — the number of test cases.
The first and only line of each test case contains two integers and (, ).
Output
For each test case, output the minimal .
思路
将下标按 分组,若 可被 整除则 ,因此约束仅发生在同一组内
同一组内任意两位置字符必须不同,因此每组最多容纳 个位置,否则鸽巢原理必有重复字母
长度为 时共有 组,各组大小为 或 ,最大组大小为
可行当且仅当 ,等价于
当 时可构造,每个余数组依次填入 个不同字母,组与组之间允许重复
因此最小不可行长度为 ,直接输出 即可
代码
#include <bits/stdc++.h>
using namespace std;
int main() { int t; cin >> t; while (t --) { int k, x; cin >> k >> x;
int ans = k * x + 1;
cout << ans << endl; }} Blackslex-and-Password
https://github.com/posts/blackslex-and-password/