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 ...
随机推荐
- Ext如何Gird中如何显示时间类型的列?
rt,后台bean中的字段属性是Date类型,前台的model中的字段属性也设置为date类型,但是还是显示不出来,如何解决呢? 直接代码: grid中的COLUMN: Model中的定义:
- cocos2dx游戏 地图
#include "HelloWorld.h" USING_NS_CC; CCScene* MyHelloWorld::scene() { // 'scene' is an aut ...
- rsync客户端命令使用简介
rsync是linux下很流行的增量备份工具,也支持本地文件(夹)复制至远程,而且支持只传输增量部分,也是一个代码(程序)发布的好工具. 基本用法如下: rsync [一堆选项] 源文件(夹) 目标文 ...
- Mac OS X 安装Ruby
安装CocoaPods第一步 起因:重装系统后需要重新安装CocoaPods网上搜了下发现很多都过时了,已经不能用了.而且taobao Gems源已经停止服务,现在有ruby-china提供服务 PS ...
- QT应用程序 安装路径中文异常问题
[1]QT 安装中文路径启动异常问题 最近在搞一个很简单的QT应用程序,开发环境VS2017 + QT5.9,线上异常报错:安装中文路径下启动崩溃~~~~ 最后,本地调试Debug版本,发现安装中文路 ...
- 一站式WPF--依赖属性(DependencyProperty)
2009-10-20 11:32 by 周永恒, 22441 阅读, 24 评论, 收藏, 编辑 书接上文,前篇文章介绍了依赖属性的原理和实现了一个简单的DependencyProperty(DP), ...
- Coursera machine learning 第二周 quiz 答案 Linear Regression with Multiple Variables
https://www.coursera.org/learn/machine-learning/exam/7pytE/linear-regression-with-multiple-variables ...
- python基础-------python2.7教程学习【廖雪峰版】(二)
2017年6月7日14:59:27任务: 看完python基础1.计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文 ...
- Pipeline模式(netty源码死磕6)
精进篇:netty源码死磕6 巧夺天工--Pipeline模式揭秘 1. 巧夺天工--Pipeline模式揭秘 1.1. Pipeline模式简介 管道的发名者叫,Malcolm Douglas M ...
- 【题解】Cutting Game
[题解]Cutting Game vjudge 谈谈对\(sg\)函数的理解? 浅谈公平组合游戏IGC //@winlere #include<cstring> #include<c ...