The harmonic value of the permutation p1,p2,⋯pn is
Mr. Frog is wondering about the permutation whose harmonic value is the strictly k-th smallest among all the permutations of [n].
∑i=1n−1gcd(pi.pi+1)
Mr. Frog is wondering about the permutation whose harmonic value is the strictly k-th smallest among all the permutations of [n].
InputThe first line contains only one integer T (1≤T≤100), which indicates the number of test cases.
For each test case, there is only one line describing the given integers n and k (1≤2k≤n≤10000).
Output
For each test case, output one line “Case #x: p1 p2 ⋯ pn”, where x is the case number (starting from 1) and p1 p2 ⋯ pn is the answer.
Sample Input
2 4 1 4 2
Sample Output
Case #1: 4 1 3 2 Case #2: 2 4 1 3
就是找一个数列使所有下标相邻数的gcd最大为k的序列。
两个相邻的自然数gcd一定为1。gcd(k, 2*k)=k。
// Asimple #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <queue> #include <vector> #include <string> #include <cstring> #include <stack> #include <set> #include <map> #include <cmath> #define INF 0x3f3f3f3f #define debug(a) cout<<#a<<" = "<<a<<endl #define test() cout<<"============"<<endl #define CLS(a,v) memset(a, v, sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn = 10+5; const ll mod = 1e9+7; ll n, m, T, len, cnt, num, ans, Max, k; void input(){ cin >> T; int cas = 1; while( T -- ) { cin >> n >> k; cout << "Case #" << cas++ << ": " << 2*k << " " << k; for(int i=k+1; i<=n; i++) { if( i == 2*k ) continue; cout << " " << i; } for(int i=1; i<=k-1; i++) cout << " " << i; cout << endl; } } int main() { input(); return 0; }