Harmonic Value Description

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 287    Accepted Submission(s): 184
Special Judge

Problem Description

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].

 

Input

The 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
 

Source

 
求gcd值第k小的1到n的排列。
 //2016.10.08
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int main()
{
int T, n, k, kase = ;
scanf("%d", &T);
while(T--)
{
int tmp = -;
scanf("%d%d", &n, &k);
printf("Case #%d:", ++kase);
if(k == ){
for(int i = ; i <= n; i++)
printf(" %d", i);
}else{
if(k&){
printf(" %d %d", *k, k);
for(int i = ; i <= n; i++)
{
if(i == *k)continue;
if(i == k)printf("");
else printf(" %d", i);
}
}else{
printf(" %d %d", *k, k);
for(int i = ; i <= n; i++)
{
if(i == k || i == *k)continue;
else printf(" %d", i);
}
}
}
printf("\n");
} return ;
}

HDU5916的更多相关文章

随机推荐

  1. Lua学习系列(二)

    资源整理: 风云老师博客: http://blog.codingnow.com/eo/luaoeeeaeau/ 知乎: https://www.zhihu.com/question/20736660 ...

  2. SQL Server 2012 - Transact-SQL

    变量 --全局变量 select @@VERSION --局部变量 declare @i int set @i=5 select @i 通配符:   like   'joh%',  %任意长度的任意字 ...

  3. 编写一个python脚本功能-备份

    版本一 解决方案当我们基本完成程序的设计,我们就可以编写代码了,它是对我们的解决方案的实施.版本一例10.1 备份脚本——版本一 #!/usr/bin/python # Filename: backu ...

  4. (简单) POJ 2750 Potted Flower,环+线段树。

    Description The little cat takes over the management of a new park. There is a large circular statue ...

  5. Vue.js起步

    Vue.js是一套构建用户界面的 渐进式框架,Vue 采用自底向上增量开发的设计,Vue 的核心库只关注视图层.Vue 完全有能力驱动采用单文件组件和 Vue 生态系统支持的库开发的复杂单页应用. V ...

  6. Android 状态栏通知Notification、NotificationManager详解

    http://www.cnblogs.com/onlyinweb/archive/2012/09/03/2668381.html

  7. jqGrid简述

    转自:http://www.blogjava.net/ilovebabyfat/archive/2012/04/06/373456.html jqGrid学习之 ------------- 安装 1. ...

  8. print打印网页相关

    作者:zccst 1,CSS <link href="/style/print.css" rel="stylesheet" type="text ...

  9. iOS 主动抛出异常

    http://blog.csdn.net/jymn_chen/article/details/38096749 http://blog.sina.com.cn/s/blog_7270a06c0101b ...

  10. CSS判断不同分辨率显示不同宽度布局CSS3技术支持IE6到IE8

    CSS判断不同分辨率浏览器(显示屏幕)显示不同宽度布局CSS3技术支持IE6到IE8.将用到css3 @media样式进行判断,但IE9以下版本不支持CSS3技术,这里DIVCSS5给大家介绍通过JS ...