C
题意:给你一个字符串,求字典序第k小的排列
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s;
int k;
signed main(){
cin >> s >> k;
sort(s.begin(), s.end());
while(k -- > 1)
next_permutation(s.begin(), s.end());
cout << s << endl;
}
D
题意:给你N个数(a_1, ...,a_N),求1~M中所有能够满足和N个数全部互质的数
方法:对(a_1, ...,a_N)质因数分解,维护一下其中包括的质因数种类,然后循环1~M中的每一个k,对k分解质因数,如果k的质因数和(a_1, ...,a_N)中包含的质因数没有重合,k就是一个答案
#include<iostream>
#include<vector>
using namespace std;
const int N = 100010;
int n, m;
int st[N];
int main(){
cin >> n >> m;
for(int i = 0; i < n; i ++){
int a;
cin >> a;
for(int j = 2; j <= a / j; j ++)
if(a % j == 0){
st[j] = 1;
while(a % j == 0) a /= j;
}
if(a > 1) st[a] = 1;
}
vector<int> res;
for(int i = 1; i <= m; i ++){
int t = 0, k = i;
for(int j = 2; j <= k / j; j ++)
if(k % j == 0){
if(st[j]) t = 1;
while(k % j == 0) k /= j;
}
if(k > 1 && st[k]) t = 1;
if(!t) res.push_back(i);
}
cout << res.size() << endl;
for(auto t : res) cout << t << endl;
}