Codeforces Round #256 (Div. 2) E. Divisors 因子+dfs
2 seconds
256 megabytes
standard input
standard output
Bizon the Champion isn't just friendly, he also is a rigorous coder.
Let's define function f(a), where a is a sequence of integers. Function f(a) returns the following sequence: first all divisors of a1 go in the increasing order, then all divisors of a2 go in the increasing order, and so on till the last element of sequence a. For example,f([2, 9, 1]) = [1, 2, 1, 3, 9, 1].
Let's determine the sequence Xi, for integer i (i ≥ 0): X0 = [X] ([X] is a sequence consisting of a single number X), Xi = f(Xi - 1) (i > 0). For example, at X = 6 we get X0 = [6], X1 = [1, 2, 3, 6], X2 = [1, 1, 2, 1, 3, 1, 2, 3, 6].
Given the numbers X and k, find the sequence Xk. As the answer can be rather large, find only the first 105 elements of this sequence.
A single line contains two space-separated integers — X (1 ≤ X ≤ 1012) and k (0 ≤ k ≤ 1018).
Print the elements of the sequence Xk in a single line, separated by a space. If the number of elements exceeds 105, then print only the first 105 elements.
6 1
1 2 3 6
4 2
1 1 2 1 2 4
10 3
1 1 1 2 1 1 5 1 1 2 1 5 1 2 5 10
题意:给你一个数,分解k次;
每次将每个数分解成它的质因数,个数>=1e5不输出;
思路:枚举质因数,dfs求解,详见代码;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=2e5+,M=4e6+,inf=1e9+;
ll x,k,flag;
set<ll>s;
set<ll>::iterator it;
ll p[N],len;
void dfs(ll x,ll step)
{
if(step>k)return;
if(flag>=)return;
if(step==k||x==)
{
if(flag>=)return;
printf("%lld ",x);
flag++;
return;
}
for(ll i=;i<len;i++)
{
ll v=p[i];
if(v>x)break;
//cout<<v<<"cccc"<<x<<endl;
if(x%v==)
dfs(v,step+);
}
}
int main()
{
scanf("%lld%lld",&x,&k);
len=;
for(ll i=;i*i<=x;i++)
{
if(i*i==x)
p[len++]=i;
else if(x%i==)
p[len++]=i,p[len++]=x/i;
}
sort(p,p+len);
flag=;
dfs(x,);
return ;
}
Codeforces Round #256 (Div. 2) E. Divisors 因子+dfs的更多相关文章
- Codeforces Round #256 (Div. 2) E Divisors
E. Divisors Bizon the Champion isn't just friendly, he also is a rigorous coder. Let's define functi ...
- Codeforces Round #256 (Div. 2)
A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)
转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...
- Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)
题目链接:http://codeforces.com/contest/448/problem/B --------------------------------------------------- ...
- Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)
解题报告 四种情况相应以下四组数据. 给两字符串,推断第一个字符串是怎么变到第二个字符串. automaton 去掉随意字符后成功转换 array 改变随意两字符后成功转换 再者是两个都有和两个都没有 ...
- Codeforces Round #256 (Div. 2)总结
这次CF状态之悲剧,比赛就别提了.后来应该好好总结. A题:某个细节没考虑到,导致T了 代码: #include<cstdio> #include<cstring> #incl ...
- Codeforces Round #256 (Div. 2) 题解
Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #256 (Div. 2) A. Rewards
A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table 二分法
D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input st ...
随机推荐
- 【cocos2dx开发技巧10】cocosStudio的集成以及c++11的新特性
转发.请保持地址:http://blog.csdn.net/stalendp/article/details/38880997 非常长时间没有碰cocos2dx了,近期又用起来了.花了好几个小时又一次 ...
- Atitit.常见的4gl 第四代编程语言 与 dsl
Atitit.常见的4gl 第四代编程语言 与 dsl 1. 4gl dsl发展历史1 2. 4gl dsl的特点1 3. 常见的4gl 第四代编程语言 dsl2 4. 未来趋势与标准2 4.1.1 ...
- JAVA问题之泛型数组
java中类似下面的代码编译器是会报错的: LinkedList<LinkedList<String>>[] li=new LinkedList<LinkedList ...
- linux VI模式下批量修改文件内容
1. :s/vivian/sky/ 替换当前行第一个 vivian 为 sky :s/vivian/sky/g 替换当前行所有 vivian 为 sky 2. ...
- cxf 创建动态webService
D:\developTools\apache-cxf-2.5.2\samples\wsdl_first_dynamic_client CXF 方法 cxf方法 serviceInfo.getBindi ...
- windows下XAMPP安装php_memcache扩展
windows下XAMPP安装php_memcache扩展 首先下载phpmemcache,地址为: http://up.2cto.com/2012/0522/20120522094758371.ra ...
- Rancher探秘二:安装Rancher
环境准备 本次安装的是最新版本v2.1.5. 准备Linux环境,需要64位版本,在系统上安装docker,版本17.03.2 安装 docker安装, 登录到Linux服务器上,运行如下命令:sud ...
- html5小趣味知识点系列(一)pubdate
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Intellij idea 切换SVN路径
一直不懂如何切换路径,每次都是删除---->检出:本地源码都不能保存下来,非常麻烦 //在idea中svn切换到新分支:[vcs] -> [subversion] -> [updat ...
- ios 手势返回<1>
极其简单取巧的方法 iOS7之后是有侧滑返回手势功能的.注意,也就是说系统已经定义了一种手势,并且给这个手势已经添加了一个触发方法(重点).但是,系统的这个手势的触发条件是必须从屏幕左边缘开始滑动.我 ...