• Harmonic Value Description HDU


    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;
    } 
  • 相关阅读:
    沮丧
    实例讲解《Microsoft AJAX Library》(1):DomElement类
    linux0.12系统调用
    关于中断
    dd写img
    linux系统中堆栈的使用方法
    浅析程序的装载
    SourceInsight3.5序列号
    区分进程的逻辑地址空间中段和cpu分段机制中段的概念
    32位计算机的4G可寻址空间
  • 原文地址:https://www.cnblogs.com/Asimple/p/7428967.html
Copyright © 2020-2023  润新知