zoukankan      html  css  js  c++  java
  • 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;
    } 
  • 相关阅读:
    linux下mysql区分大小写的内容
    jar包 pom
    项目的考虑
    webservice
    MySQL外键设置中的的 Cascade、NO ACTION、Restrict、SET NULL
    JVM参数最佳实践:元空间的初始大小和最大大小
    JVM问题排查工具:Serviceability-Agent介绍
    Spring Boot 2.x基础教程:构建RESTful API与单元测试
    彻底搞懂JVM类加载器:基本概念
    如何解决90%的问题?10位阿里大牛公布方法
  • 原文地址:https://www.cnblogs.com/Asimple/p/7428967.html
Copyright © 2011-2022 走看看