首页 > 代码库 > HDU5916
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
Mr. Frog is wondering about the permutation whose harmonic value is the strictly k-th smallest among all the permutations of [n].
∑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).
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
2016中国大学生程序设计竞赛(长春)-重现赛
求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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。