Codeforces Round #256 (Div. 2) E Divisors
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
#include<stdio.h>
#include<map>
#include<algorithm>
#define MAXN 20000000
using namespace std;
typedef long long LL;
LL ys[];int tot=;int tt2=;
int tail[];int head[];
int aft[MAXN];LL p[MAXN];
LL n,k;
map<LL,int>bh;
void line(int j,int i)
{
tt2++;if(!tail[j])head[j]=tt2;p[tt2]=i;aft[tail[j]]=tt2;tail[j]=tt2;
}
void init()
{
for(LL i=;i*i<=n;i++)
if(n%i==)
{
ys[++tot]=i;
if(i*i!=n)
ys[++tot]=n/i;
}
sort(ys+,ys++tot);
for(int i=;i<=tot;i++)bh[ys[i]]=i;
for(int i=;i<=tot;i++)
for(int j=;j<=i;j++)
if(ys[i]%ys[j]==)line(i,j);
}
int dfs(int now,LL dep,int need)
{
if(ys[now]==)
{
printf("1 ");
return ;
}
if(dep==k)
{
int us=need;
for(int u=head[now];u&&need;need--,u=aft[u])
printf("%I64d ",ys[p[u]]);
return us-need;
}
int us=need;
for(int u=head[now];u&&need;need-=dfs(p[u],dep+,need),u=aft[u]);
return us-need;
}
int main()
{
scanf("%I64d%I64d",&n,&k);if(k>)k=;
init();
if(!k)
{
printf("%I64d\n",n);
return ;
}
dfs(bh[n],,);
return ;
}
Codeforces Round #256 (Div. 2) E Divisors的更多相关文章
- Codeforces Round #256 (Div. 2) E. Divisors 因子+dfs
E. Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- 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)
A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...
- Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)
解题报告 四种情况相应以下四组数据. 给两字符串,推断第一个字符串是怎么变到第二个字符串. automaton 去掉随意字符后成功转换 array 改变随意两字符后成功转换 再者是两个都有和两个都没有 ...
- 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 ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table
主题链接:http://codeforces.com/contest/448/problem/D 思路:用二分法 code: #include<cstdio> #include<cm ...
随机推荐
- Docker Compose practice
Docker Compose 什么是 Docker-Compose? Compose 可以让用户在集群中部署分布式应用.简单的说,Docker Compose 属于一个"应用层"的 ...
- Python操作Excle
python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库.可从这里下载https://pypi.python.org/pypi.下面分别记录p ...
- Jenkins无法安装插件或首次安装插件界面提示Offline
一.首先点击系统管理 二.点击插件管理 三.选择高级管理 四.将升级站点中的https改成http即可
- Ubuntu_安装Wiz笔记
前言 安装完成了Linux,有了搜狗输入法,我们还需要笔记软件,本文主要介绍如何安装为知笔记 安装步骤 找到wiz官网:http://www.wiz.cn/ 获取Linux安装教程 安装QT 下载的Q ...
- collection.toArray(new String[0])中new String[0]的作用
new string[0]的作用 比如:String[] result = set.toArray(new String[0]); Collection的公有方法中,toArray()是比较重要的一个 ...
- java基础31 List集合下的Vector集合
单例集合体系: ---------| collection 单例集合的根接口--------------| List 如果实现了list接口的集合类,具备的特点:有序,可重复 注:集合 ...
- 前端程序员必知的30个Chrome扩展-[转载]
谷歌Chrome浏览器是网络上可用的最好浏览器之一,并且自2011年11月超越了Firefox浏览器之后,已经成为了互联网上占主导地位的浏览器.今天,HTML5中国与大家分享一些实用的谷歌Chrome ...
- 阿里云宝塔Linux服务器管理面版初始化地址不能登入(原创)
宝塔面板是一款可以让Linux服务器实现图形可视化操作的集成系统. 安装好以后,页面初始化登录地址http://{您的服务器IP}:888不能登入. 不能登入通常是我们没有权限访问,需要更改安全组赋予 ...
- Entity Framework Code First 在Object Join Linq查询时出现全表查询的语句。
最近一个项目,使用微软的Entity Framework的ORM框架的项目,部署到现场后,出现了系统缓慢,多个客户端的内存溢出崩溃的问题. 打开了SQL Server Profiler(SQL Ser ...
- GridView练习题
package com.example.wang.myapplication; import android.os.Bundle; import android.support.v7.app.AppC ...