Harmonic Value Description
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 410 Accepted Submission(s): 259
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
题意很蛋疼 2组样例 4 1 求 1,2,3,4全排列 每个排列都有一个∑i=1n−1gcd(pi.pi+1)
(求相邻两个数的gcd)
如果值相同也算在一个排名 求第k小的其中一个排列
大胆猜想吧(2k<n) 把n个偶数放在一起就能多(n-1)
然后其他的数放按顺序输出(还是可以两两GCD为1猜想的)
#include<stdio.h>
#include<string.h>
int vis[10010];
int main()
{
int t,i,h,n,k;
scanf("%d",&t);
for(h=1; h<=t; h++)
{
scanf("%d%d",&n,&k);
memset(vis,0,sizeof(vis));
for(i=1; i<=k; i++)
vis[2*i]=1;
printf("Case #%d:",h);
for(i=1; i<=n; i++)
if(vis[i])
printf(" %d",i);
for(i=1; i<=n; i++)
if(!vis[i])
printf(" %d",i);
printf("\n");
}
return 0;
}