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得到的数肯定要小于数 ...
随机推荐
- Python 操作Gitlab-API 实现批量的合并分支
1.需求:每次大批量上线完成后,都会进行将hotfix合并到Master,合并到test/uat等等重复操作(上线发布后自动合并master已完成). 2.现实:在完成发布后自动合并master后,可 ...
- devicemapper存储驱动下镜像的存储
docker配置devicemapper存储驱动 #查看当前使用的存储驱动,默认为overlay docker info | grep -i storage #停止dockersystemctl st ...
- 【Linux系列】配置Centos 7的软件源(二)
目的 本文主要介绍以下内容: 设置centos的国内软件源,默认源都是国外的下载软件超级麻烦. ssh登录 下载一个shell或者cmder ssh root@192.168.10.18 #上篇设置的 ...
- 扛把子组Scrum立会报告+燃尽图 07
此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/8684 一.小组情况组长:迟俊文组员:宋晓丽 梁梦瑶 韩昊 刘信鹏队名:扛把 ...
- Hadoop运行模式
Hadoop运行模式 (1)本地模式(默认模式): 不需要启用单独进程,直接可以运行,测试和开发时使用. 即在一台机器上进行操作,仅为单机版. 本地运行Hadoop官方MapReduce案例 操作命令 ...
- Stream系列(一)Filter方法使用
Filter 是过滤器,也可以当查询方法使用 EmployeeTestCase.java package com.example.demo; import lombok.extern.log4j.Lo ...
- 计蒜客 The Preliminary Contest for ICPC Asia Nanjing 2019
F Greedy Sequence You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each ...
- 深入浅出Spring(一)
现在很多的企业级项目中基本上都会用到了Spring框架,那么为什么会出现Spring,Spring是什么?这次的博文我主要为大家简单介绍一下Spring. Java EE优缺点 我们都知道在2003年 ...
- python名称空间和作用域
python名称空间和作用域 名称空间 名称空间:例如a=1000,python解释器会开辟一块新的内存来存贮1000这个变量值,然后会有一个a指向这个1000,那么a存在哪里?其实他和变量值差不多, ...
- 系统目录结构、ls命令、文件类型、alias命令 使用介绍
1周第5次课(3月23日) 课程内容: 2.1/2.2 系统目录结构2.3 ls命令2.4 文件类型2.5 alias命令 Linux系统目录结构 在Linux系统里面也是同样存在很多文件和文件夹,而 ...