A. We Got Everything Covered!
题意:t组数据,每组数据给两个正整数n和k。找到一个字符串,使所有长度为n的字符串都可以组成使用前k个小写字母座位s的子序列出现。输出长度最小的答案。注:如果可以通过从b中删除一些字符(可能为零)而不改变其余字符的顺序来获得A,则字符串A称为另一个字符串b的子序列。
input
4
1 2
2 1
2 2
2 3
output
ab
aa
baab
abcbac
题解:根据题目样例分析可得,只需交替输出前k个字母,一共n次即可。
代码实现:
#include<iostream>
using namespace std;
const int N = 2e5;
void solve()
{
int n, k;
cin >> n >> k;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < k; j++)
cout << (char)('a' + j);
}
cout << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while(t--)
solve();
return 0;
}
B. A Balanced Problemset?
题意:给t组数据,每组数据给出一个x和n,将x分为n个数之和,求他们的最大公因数gcd
题解:分解质因数问题,将x分为n个数,求他们的最大公因数gcd,很明显gcd一定是x的因数,并且gcd*n<=x,用 根号枚举x的因数即可
代码实现:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5;
void solve()
{
int n, x, res = 1;
cin >> x >> n;
for(int i = 1; i * i <= x; i++)
{
if(x % i == 0)
{
if(n <= x / i)
res = max(res, i);
if(n <= i)
res = max(res, x/i);
}
}
cout << res << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while(t--)
solve();
return 0;
}