CodeForces - 1059C Sequence Transformation (GCD相关)
Let's call the following process a transformation of a sequence of length nn.
If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a sequence of nn integers: the greatest common divisors of all the elements in the sequence before each deletion.
You are given an integer sequence 1,2,…,n1,2,…,n. Find the lexicographically maximum result of its transformation.
A sequence a1,a2,…,ana1,a2,…,an is lexicographically larger than a sequence b1,b2,…,bnb1,b2,…,bn, if there is an index ii such that aj=bjaj=bj for all j<ij<i, and ai>biai>bi.
Input
The first and only line of input contains one integer nn (1≤n≤1061≤n≤106).
Output
Output nn integers — the lexicographically maximum result of the transformation.
Examples
3
1 1 3
2
1 2
1
1
Note
In the first sample the answer may be achieved this way:
- Append GCD(1,2,3)=1(1,2,3)=1, remove 22.
- Append GCD(1,3)=1(1,3)=1, remove 11.
- Append GCD(3)=3(3)=3, remove 33.
We get the sequence [1,1,3][1,1,3] as the result.
题目大意:
每次从1..n中删去一个数,求剩余数GCD的可能最大字典序序列。
当n>=4时,所有数中有2这个质因子的一定占多数,所以将不含2质因子的数删除,再将剩下的数除以二,又转化成1..n/2的输出问题。(详见代码)
这题是练习的时候自主想出的,纪念下。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stack> typedef long long lol; using namespace std; const int maxn=; int main()
{
int n;
scanf("%d",&n);
for(int i=;;)
{
if(n==)
{
printf("%d\n",*i);
break;
}
else if(n==)
{
printf("%d %d\n",*i,*i);
break;
} else if(n==)
{
printf("%d %d %d\n",*i,*i,*i);
break;
}
else
{
for(int j=;j<=(n+)/;j++)
printf("%d ",*i);
n/=;
i*=;
}
}
return ;
}
CodeForces - 1059C Sequence Transformation (GCD相关)的更多相关文章
- [CodeForces]1059C Sequence Transformation
构造题. 我递归构造的,发现如果N>3的话就优先删奇数,然后就把删完的提取一个公约数2,再重复操作即可. 具体原因我觉得是因为对于一个长度大于3的序列,2的倍数总是最多,要令字典序最大,所以就把 ...
- codeforces 1059C. Sequence Transformation【构造】
题目:戳这里 题意:有1,2,3...n这n个数,求一次这些数的gcd,删去一个数,直到剩下一个数为止.输出这n个gcd的最大字典序. 解题思路:一开始的gcd肯定是1,要让字典序最大,我们可以想到下 ...
- Codeforces Round #514 (Div. 2) C. Sequence Transformation(递归)
C. Sequence Transformation 题目链接:https://codeforces.com/contest/1059/problem/C 题意: 现在有1~n共n个数,然后执行下面操 ...
- 【CF 1059C】 Sequence Transformation 数学
C. Sequence Transformation:http://codeforces.com/contest/1059/problem/C 题意 给你一个n,第一次输出1-n个数的gcd,然后你可 ...
- CF1059C Sequence Transformation 题解
这几天不知道写点什么,状态也不太好,搬个题上来吧 题意:给定一个数n,设一个从1到n的序列,每次删掉一个序列中的数,求按字典序最大化的GCD序列 做法:按2的倍数找,但是如果除2能得到3的这种情况要特 ...
- Codeforces 486C Palindrome Transformation(贪心)
题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N.指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:事实上仅仅要 ...
- Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
- codeforces 894C - Marco and GCD Sequence - [有关gcd数学题]
题目链接:https://cn.vjudge.net/problem/CodeForces-894C In a dream Marco met an elderly man with a pair o ...
- Codeforces Round #514 (Div. 2) C. Sequence Transformation 思维构造
题意 给出一个1-n的集合 gcd 集合里面的所有数 得到的 一个 数 然后自己选择删去一个数 要使得到的数 构成的数列 的字典序最大 思路: gcd所有数 那gcd得到的数肯定要小于数 ...
随机推荐
- Linux菜鸟——常见命令一 查看及创建目录文件等命令
命令行提示符 [root@localhost ~]# [当前用户名@主机名 当前所在目录]$ linux 超级用户 root window 超级用户 administartor # 超级用户 $ 普通 ...
- 使用图数据库 Nebula Graph 数据导入快速体验知识图谱 OwnThink
前言 本文由 Nebula Graph 实习生@王杰贡献. 最近 @Yener 开源了史上最大规模的中文知识图谱--OwnThink(链接:https://github.com/ownthink/Kn ...
- 研究Java语言的编译器和虚拟机源代码
现在使用Java语言的人很多,但是了解Java语言实现的人非常少.如果要研究Java语言的实现,推荐研究Javac和虚拟机HotSpot的源代码实现,其中Javac相当于Java编译的前端,HotSp ...
- 驰骋工作流系统-Java共工作流引擎配置定时任务
关键词:工作流定时任务 流程引擎定时任务设置 工作流系统定时任务配置 开源工作流引擎 开源工作流系统 一.定时任务的作用 发送邮件,发送短信. 处理节点自动执行的任务.比如:一个节点的待办工作是 ...
- HTML 空元素(转)
HTML 空元素 在 HTML 中,通常在一个空元素上使用一个闭标签是无效的.例如,<input type="text"> </input> 的闭标签是无效 ...
- html background-image 图片打开失败的原因
写网页的时候遇到一个问题,在样式表里面引用background-image,没有出现效果.查了一下是提取图片的路径不对,记录下遇到问题以及解决方法. 1.系统自带url 引号问题 这个最坑,以为系统就 ...
- Linux监控平台介绍、zabbix监控介绍、安装zabbix、忘记Admin密码如何做
7月6日任务 19.1 Linux监控平台介绍19.2 zabbix监控介绍19.3/19.4/19.5 安装zabbix19.6 忘记Admin密码如何做 19.1 Linux监控平台介绍 一般大公 ...
- 源码安装php7.2
`# 安装依赖包 yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel \ libjpeg libjpeg-devel lib ...
- 对python的初步了解
一,Python简介 Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具 ...
- 走近深度学习,认识MoXing:初识华为云ModelArts的王牌利器 — MoXing
[摘要] 本文为MoXing系列文章第一篇,主要介绍什么是MoXing,MoXing API的优势以及MoXing程序的基本结构. MoXing的概念 MoXing是华为云深度学习服务提供的网络模型开 ...