Harmonic Value Description HDU - 5916
Mr. Frog is wondering about the permutation whose harmonic value is the strictly k-th smallest among all the permutations of [n].
InputThe 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
就是找一个数列使所有下标相邻数的gcd最大为k的序列。
两个相邻的自然数gcd一定为1。gcd(k, 2*k)=k。
// Asimple
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define INF 0x3f3f3f3f
#define debug(a) cout<<#a<<" = "<<a<<endl
#define test() cout<<"============"<<endl
#define CLS(a,v) memset(a, v, sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = +;
const ll mod = 1e9+;
ll n, m, T, len, cnt, num, ans, Max, k; void input(){
cin >> T;
int cas = ;
while( T -- ) {
cin >> n >> k;
cout << "Case #" << cas++ << ": " << *k << " " << k;
for(int i=k+; i<=n; i++) {
if( i == *k ) continue;
cout << " " << i;
}
for(int i=; i<=k-; i++) cout << " " << i;
cout << endl;
}
} int main() {
input();
return ;
}
Harmonic Value Description HDU - 5916的更多相关文章
- HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))
Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- HDU 5916: Harmonic Value Description
题目描述 The harmonic value of the permutation $p_1,p_2,\cdots p_n$ is$$\sum_{i=1}^{n-1} gcd(p_i.p_{i+1} ...
- HDU 5916 Harmonic Value Description (构造)
题意:给你 n 和 m,求一个1-n的排列,使得∑gcd(Ai,Ai+1) 恰为第 m 小. 析:可以想到最小的就是相邻都互质,然后依次,第 m 小就可以有一个是gcd为 k,然后其他的为1喽. 那 ...
- Harmonic Value Description(构造题)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission ...
- Hdu 1214 圆桌会议
圆桌会议 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 2048 神、上帝以及老天爷(错排)
神.上帝以及老天爷 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- hdu 1491 Octorber 21st
Octorber 21st Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDOJ(HDU) 1491 Octorber 21st
Problem Description HDU's 50th birthday, on Octorber 21st, is coming. What an exciting day!! As a st ...
- hdu2574 Hdu Girls' Day (分解质因数)
Hdu Girls' Day Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- 【Java】-NO.16.EBook.4.Java.1.008-【疯狂Java讲义第3版 李刚】- 集合/容器
1.0.0 Summary Tittle:[Java]-NO.16.EBook.4.Java.1.008-[疯狂Java讲义第3版 李刚]- 集合 Style:EBook Series:Java Si ...
- bat脚本简单命令
1.if 判断 (1.1)判断字符串是否为空: if "%var1%" == " " ( echo null) else(echo not null ) (1. ...
- express框架之session 存储
1.express-session 是基于express框专门用于处理session的中间件.这里不谈express-session怎么安装,只给出相应的实例代码.另外,session的认证机制离不开 ...
- JDB调试
- java开发前的配置
JAVA语言是1995年由Sun公司退出的一门高级编程语言,在2009年4月20被ORACLE公司收购 看看java体系图
- 前端 json 导出 excel
参考:https://blog.csdn.net/abel_yang/article/details/78684786 在github上有大神提供现成的插件,非常感谢 https://cuikangj ...
- vue中强制刷新的bug处理
vue是单页面应用,跳转路由也是局部刷新,这里就拿后台管理系统而言,如果你的后台管理系统是左右布局,你不会遇到这样的问题,但是如果你的后台管理系统是上左右布局,你就会遇到这个问题,一级菜单在最上面,二 ...
- LeetCode155.最小栈
设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- 删除栈顶的元素. top() -- 获取栈顶元素. ...
- itextsharp利用模板生成pdf文件笔记
iTextSharp是一款开源的PDF操作类库,使用它可以快速的创建PDF文件. 中文参考网站:http://hardrock.cnblogs.com/ http://pdfhome.hope.com ...
- 学习笔记<1>技术体系结构
Android的系统架构采用了分层架构的思想,如上图所示.从上层到底层共包括四层,分别是 1.应用程序程序层 2.应用框架层 3.系统库和Android运行时 4.Linux内核. 每 ...