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. EOS config 大全

    https://eosfans.io/topics/930 bnet_plugin bnet-endpoint: 所监听的传入链接的端点. 默认:0.0.0.0:4321 bnet-follow-ir ...

  2. golang gui library 库

    andlabs/ui已经重写,稳定性增强,但是组件很少,只提供了几种基础的控件,慎用.gxui死了,别用.linuxdeepin转QT了,所以…… windows系统最好的选择是walk. 首先,写w ...

  3. Spark DataFrame列的合并与拆分

    版本说明:Spark-2.3.0 使用Spark SQL在对数据进行处理的过程中,可能会遇到对一列数据拆分为多列,或者把多列数据合并为一列.这里记录一下目前想到的对DataFrame列数据进行合并和拆 ...

  4. [LeetCode] 824. Goat Latin_Easy

    A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...

  5. 实现多线程异步自动上传本地文件到 Amazon S3

    最近抽空做个小工具,使用AWSSDK 对本地文件目录监控,并自动同步上传文件到S3 的过程,使用的是多线程异步上传,针对大文件进行了分块 参考文献: https://www.codeproject.c ...

  6. C#使用HttpWebRequest与HttpWebResponse模拟用户登录

    模拟艺龙旅游网登录 想模拟登录,首先整理一下流程 1.通过360浏览器(IE,火狐等等)F12开发人员工具抓到相关数据 2.获取验证码(拿到cookie),登录时也需要使用 3.登录 -------- ...

  7. windows 服务器硬盘的分区

    进入Server 2012的操作系统,打开CMD框,输入:diskmgmt.msc,回车. 操作完第一步后会弹出“磁盘管理”的框.鼠标右键点击红框所在位置,选中“压缩卷”. 在“输入压缩空间量(MB) ...

  8. gitlab RPM卸载 & 安装 && 升级(9.0.13-》9.5.9-》10.0->10.3.9->10.6.6-》10.8-》11.0)

    版本:9.0.3 升级版本:9.0.13 一,停止服务 gitlab-ctl stop unicorn gitlab-ctl stop sidekiq gitlab-ctl stop nginx 二, ...

  9. tp命名空间

    namespace   Home\Controller;  命名空间   根命名空间下的类所在的文件夹use Think\Controller; 使用   根命名空间下的controller类 顶头写 ...

  10. Unity shader学习之切线空间下计算凹凸映射

    切线空间,即使用顶点的切线作为x轴,法线作为z轴,法线与切线的叉积作为y轴. 使用切线空间存储法线,使得法线纹理可以复用,很好. 在切线空间中计算光照,比在世界空间中计算光照少了很多计算量.在切线空间 ...