Harmonic Value Description HDU - 5916

时间:2023-03-09 07:38:05
Harmonic Value Description HDU - 5916
The harmonic value of the permutation p1,p2,⋯pn is
∑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 = +;
const ll mod = 1e9+;
ll n, m, T, len, cnt, num, ans, Max, k; void input(){
cin >> T;
int cas = ;
while( T -- ) {
cin >> n >> k;
cout << "Case #" << cas++ << ": " << *k << " " << k;
for(int i=k+; i<=n; i++) {
if( i == *k ) continue;
cout << " " << i;
}
for(int i=; i<=k-; i++) cout << " " << i;
cout << endl;
}
} int main() {
input();
return ;
}