首页 > 其他 > 详细

HDU5916

时间:2016-10-08 23:44:05      阅读:369      评论:0      收藏:0      [点我收藏+]

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=1n1gcd(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 (1T100), which indicates the number of test cases.

For each test case, there is only one line describing the given integers n and k (12kn10000).
 

 

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的排列。
 1 //2016.10.08
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int T, n, k, kase = 0;
11     scanf("%d", &T);
12     while(T--)
13     {
14         int tmp = -1;
15         scanf("%d%d", &n, &k);
16         printf("Case #%d:", ++kase);
17         if(k == 1){
18             for(int i = 1; i <= n; i++)
19                   printf(" %d", i);
20         }else{
21             if(k&1){
22                 printf(" %d %d", 2*k, k);
23                 for(int i = 2; i <= n; i++)
24                 {
25                     if(i == 2*k)continue;
26                     if(i == k)printf(" 1");
27                     else printf(" %d", i);
28                 }
29             }else{
30                 printf(" %d %d", 2*k, k);
31                 for(int i = 1; i <= n; i++)
32                 {
33                     if(i == k || i == 2*k)continue;
34                     else printf(" %d", i);
35                 }
36             }
37         }
38         printf("\n");
39     }
40 
41     return 0;
42 }

 

HDU5916

原文:http://www.cnblogs.com/Penn000/p/5940219.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!