Harmonic Value Description HDU - 5916

weixin_30639719發表於2020-04-05
The harmonic value of the permutation p1,p2,pn is 
i=1n1gcd(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 (1T100), which indicates the number of test cases. 

For each test case, there is only one line describing the given integers n and k (12kn10000).

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;
} 

 

轉載於:https://www.cnblogs.com/Asimple/p/7428967.html