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 ...
随机推荐
- Android模拟屏幕点击input tap替代解决方案
动机解释 本来直接使用 adb shell -> input 即可模拟 键盘事件,触屏事件keyevent ,text,tap 但是手上的这台目标Android机4.0.3系统的input只支持 ...
- const_cast去除const限制,同一片内存
本质很简单,但一些优化 和 编程上的错误,却让人看不清本质. :const_cast<type_id> (expression) 该运算符用来修改类型的const或volatile属性.除 ...
- 功能强大的图片截取修剪神器:Android SimpleCropView及其实例代码重用简析(转)
功能强大的图片截取修剪神器:Android SimpleCropView及其实例代码重用简析 SimpleCropView是github上第一个第三方开源的图片修剪截取利器,功能强大,设计良好.我个人 ...
- systemctl使用说明
# systemctl #输出已激活单元 # systemctl list-units #输出已激活单元 # systemctl --failed #输出运行失败的单元 # systemctl lis ...
- volley全然解析
一.volley是什么? 1.简单介绍 Volley是Goole在2013年Google I/O大会上推出了一个新的网络通信框架,它是开源的.从名字由来和配图中无数急促的火箭能够看出 Volley ...
- 纯JS实现动态时间
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ajax 和jsonp 不是一码事 细读详解
由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socket通讯 ...
- smarty模板 变量 运算符 表达式 流程控制 函数
① 从配置文件中读取配置: 1,在模板页面加载配置文件 html页面 不是php页面<{config_load file='fo.conf'}> 2,在需要用到配置的地方加<{#si ...
- Jmeter+Ant+Jenkins接口自动化测试框架搭建
前言 软件开发的V模型大家都不陌生,其中测试阶段分为单元测试→功能测试→系统测试→验收测试.其中单元测试一般由开发同学们自己完成,大部分测试具体实施(这里不包括用例设计)是从单体功能测试开始着手的. ...
- 【BZOJ4930】棋盘 拆边费用流
[BZOJ4930]棋盘 Description 给定一个n×n的棋盘,棋盘上每个位置要么为空要么为障碍.定义棋盘上两个位置(x,y),(u,v)能互相攻击当前仅 当满足以下两个条件: 1:x=u或y ...