Fellow me on GitHub

HDU5916

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 }

 

posted @ 2016-10-08 21:17  Penn000  阅读(234)  评论(0编辑  收藏  举报