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. AOP 在javascript 中的使用

    AOP(Aspect Oriented Programming) 意为面向切面编程 可以在不修改原有代码的情况下增加新功能,利用AOP可以对业务逻辑各个部分进行隔离,从而使得业务逻辑各部分的耦合度降低 ...

  2. Contaminated Milk

    Contaminated Milk 题目描述 Farmer John, known far and wide for the quality of the milk produced on his f ...

  3. HDU 3265 Posters

    矩形面积并,一个拆成四个 #include<cstdio> #include<cstring> #include<cmath> #include<map> ...

  4. POJ3352 Road Construction 双连通分量+缩点

    Road Construction Description It's almost summer time, and that means that it's almost summer constr ...

  5. 项目经验分享——Java常用工具类集合 转

    http://blog.csdn.net/xyw591238/article/details/51678525 写在前面     本文涉及的工具类部分是自己编写,另一部分是在项目里收集的.工具类涉及数 ...

  6. iOS关于UITabView和UIAlertController,UIAlertAction以及UINavigation,值修改的传递页面推送

    关于UITabView和UIAlertController,UIAlertAction以及UINavigation,值修改的传递 集合嵌套集合的操作 声明 两个必须的的代理 实现部分代码 - (voi ...

  7. (简单) POJ 1797 Heavy Transportation,Dijkstra。

    Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can no ...

  8. mac系统不能使用127.0.0.2的解决方案

    英语学得不好,国外这位大神的精彩解释不是特能看的懂.我模仿的试了一下. 解决方案: 1.打开mac终端 2.输入:sudo ifconfig lo0 alias 127.1.1.1 netmask 0 ...

  9. CORBA技术及实例

    CORBA技术及实例 CORBA是一种规范,它定义了分布式对象如何实现互操作.在WorldWideWeb盛行之前,非凡是java编程语言风靡之前,C++开发者基本将CORBA作为其高端分布式对象的解决 ...

  10. css01

      1.  常用属性:①color:文本颜色:②background-color:背景颜色:③font-size:文字大小: 2.  样式声明:①内部样式:style=“样式规则:”,写于作用标签内, ...