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. [QGLViewer]鼠标取点后回调

    纠结的一天:QGLViewer控件重载鼠标事件(AxMapControl类),如何在点击鼠标之后执行一个回调,通知主界面Viewer类执行一个操作. 先是考虑直接使用C风格的回调函数,在AxMapCo ...

  2. field-symbols: <ATTR> type ANY.

    field-symbols: type ANY. * importing iv_root_list type refer to if_genil_cont_root_objectlist DATA l ...

  3. 创建genil component

    1: 创建一个类继承 CL_WCF_GENIL_ABSTR_COMPONENT 2:创建 genil _ editor 创建 component, 填入该实现类. 3: genil component ...

  4. git push 提交某一个commit

    (以下情况是我们的一位开发小哥哥遇到了提交失败,来找我,我给他解决的过程,以前我也没遇到,所以记录下来) 我们会遇到这样的情况,在develop分支上,第一天修改的文件,已经执行了git commit ...

  5. Hybrid设计--核心交互

    普通网页中跳转使用a标签,这里我们要对跳转进行更多的干预,所以将全站的跳转收口到框架层,用forward去实现.拒绝用a和window.location.如果我想对所有跳转做一个处理,开动画或者对跳转 ...

  6. python 格式化字符串"%s"%

    %s    字符串 (采用str()的显示) %r    字符串 (采用repr()的显示) %c    单个字符 %b    二进制整数 %d    十进制整数 %i    十进制整数 %o    ...

  7. iOS 开发笔记 - 开发中如何实现自动检测更新APP

    1.获取当前项目APP版本号 2.拿到AppStore项目版本号 3.对比版本号,实现更新功能 直接上代码: #import "ViewController.h" //1一定要先配 ...

  8. Sklearn的使用

    初步接触要求时,从上图选自己数据所适用的方法, 首先看数据的样本是否 >50,小于则需要收集更多的数据 然后看问题适合分类.回归.聚类.降维中的哪一大类 Sklearn解决问题的一般步骤: 1. ...

  9. C# - 匿名对象取值

    在new出匿名对象的函数内可以直接调用该匿名对象的属性取值. 可是在其它函数就无法调用匿名对象的属性或方法. 这时,我们可以通过c#的反射机制取值: 文章出处:https://www.cnblogs. ...

  10. 有关Struts下载文件时报错问题

    在学习文件下载的时候,我也是按照网络课程上面老师的代码一句一句敲得,和老师的一模一样:到最后测试下载的时候出现了如下的错误: 而老师的写的代码可以完美运行,以下是跟着老师敲的代码: package c ...