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. Quick Cocos2dx Http通讯 JSON

    参考: 1 http://stackoverflow.com/questions/5975952/how-to-extract-http-message-body-in-basehttprequest ...

  2. 内核kconfig语法及原理

    语法 http://www.cnblogs.com/AP0904225/p/5967979.html 目前自己用过 一.菜单 menu "desc" endmenu 二.可配菜单 ...

  3. (简单) HDU 2612 Find a way,BFS。

    Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Nin ...

  4. JAVA基础--工厂模式

    interface Fruit{ // 定义一个水果接口 public void eat() ; // 吃水果 } class Apple implements Fruit{ public void ...

  5. pom文件说明

    http://www.blogjava.net/hellxoul/archive/2013/05/16/399345.html

  6. Mac搭建Hadoop源码阅读环境

    1.本次Hadoop源码阅读环境使用的阅读工具是idea,Hadoop版本是2.7.3.需要安装的工具包括idea.jdk.maven.protobuf等 2.jdk,使用的版本是1.8版,在jdk官 ...

  7. 贪心法基础题目 HDU

    贪心算法的基本步骤: 1.从问题的某个初始解出发.2.采用循环语句,当可以向求解目标前进一步时,就根据局部最优策略,得到一个部分解,缩小问题的范围或规模.3.将所有部分解综合起来,得到问题的最终解. ...

  8. pyhton字符编码问题--decode和encode方法

    1  decode和encode方法 字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成uni ...

  9. ymodem协议c实现(转)

    源:ymodem协议c实现 /****************************************Copyright (c)******************************** ...

  10. 微信小程序之----弹框组件modal

    modal modal类似于javascript中的confirm弹框,默认情况下是一个带有确认取消的弹框,不过点击取消后弹框不会自动隐藏,需要通过触发事件调用函数来控制hidden属性. 官方文档 ...