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

Harmonic Value Description HDU - 5916的更多相关文章

  1. HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))

    Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  2. HDU 5916: Harmonic Value Description

    题目描述 The harmonic value of the permutation $p_1,p_2,\cdots p_n$ is$$\sum_{i=1}^{n-1} gcd(p_i.p_{i+1} ...

  3. HDU 5916 Harmonic Value Description (构造)

    题意:给你 n 和 m,求一个1-n的排列,使得∑gcd(Ai,Ai+1) 恰为第  m 小. 析:可以想到最小的就是相邻都互质,然后依次,第 m 小就可以有一个是gcd为 k,然后其他的为1喽. 那 ...

  4. Harmonic Value Description(构造题)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission ...

  5. Hdu 1214 圆桌会议

    圆桌会议 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  6. hdu 2048 神、上帝以及老天爷(错排)

    神.上帝以及老天爷 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  7. hdu 1491 Octorber 21st

    Octorber 21st Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. HDOJ(HDU) 1491 Octorber 21st

    Problem Description HDU's 50th birthday, on Octorber 21st, is coming. What an exciting day!! As a st ...

  9. hdu2574 Hdu Girls' Day (分解质因数)

    Hdu Girls' Day Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. vue【指令】

    <div class="m-conbox"> <div v-text="html"></div> <div>{{ ...

  2. 几种Robust方法对比

    1.Mean Absolute Deviation http://mathbits.com/MathBits/TISection/Statistics1/MAD.html 2.Median Absol ...

  3. PHP数字字符串左侧补0、字符串填充和自动补齐的几种方法

    一.数字补0. 如果要自动生成学号,自动生成某某编号,就像这样的形式“d0000009”.“d0000027”时,那么就会面临一个问题,怎么把左边用0补齐成这样8位数的编码呢?我想到了两种方法实现这个 ...

  4. Github安全开源工具集合

    Scanners-Box是来自github平台的开源扫描仪的集合,包括子域枚举,数据库漏洞扫描程序,弱密码或信息泄漏扫描仪,端口扫描仪,指纹扫描仪和其他大型扫描仪,模块化扫描仪等.对于其他众所周知的扫 ...

  5. 21-Python3 模块

    fibo.py文件 def fib(n): a,b = 0,1 while b<n: print(b,end='') a,b = b,a+b print() def fib2(n): resul ...

  6. 20-Python3 数据结构

    2018-11-30 15:45:55 ''' 列表 ''' # list.count(x): 返回x在列表中出现的次数 a1 = [1,123.25,333,333,456.5] print(a1. ...

  7. [LeetCode] 124. Binary Tree Maximum Path Sum_ Hard tag: DFS recursive, Divide and conquer

    Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any ...

  8. [LeetCode] 884. Uncommon Words from Two Sentences_Easy tag: Hash Table

    We are given two sentences A and B.  (A sentence is a string of space separated words.  Each word co ...

  9. SQL _ Create Procedure

    -- ================================================ -- Template generated from Template Explorer usi ...

  10. Keras学习率调整

    Keras提供两种学习率适应方法,可通过回调函数实现. 1. LearningRateScheduler keras.callbacks.LearningRateScheduler(schedule) ...