首页 > 其他 > 详细

Codeforces Round #256 (Div. 2) E Divisors

时间:2014-07-18 10:21:24      阅读:419      评论:0      收藏:0      [点我收藏+]
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.

Input

A single line contains two space-separated integers — X (1 ≤ X ≤ 1012) and k (0 ≤ k ≤ 1018).

Output

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.

Sample test(s)
Input
6 1
Output
1 2 3 6 
Input
4 2
Output
1 1 2 1 2 4 
Input
10 3
Output
1 1 1 2 1 1 5 1 1 2 1 5 1 2 5 10 
bubuko.com,布布扣
 1 #include<stdio.h>
 2 #include<map>
 3 #include<algorithm>
 4 #define MAXN 20000000
 5 using namespace std;
 6 typedef long long LL;
 7 LL ys[9000];int tot=0;int tt2=0;
 8 int tail[9000];int head[9000];
 9 int aft[MAXN];LL p[MAXN];
10 LL n,k;
11 map<LL,int>bh;
12 void line(int j,int i)
13 {
14      tt2++;if(!tail[j])head[j]=tt2;p[tt2]=i;aft[tail[j]]=tt2;tail[j]=tt2;
15 }
16 void init()
17 {
18      for(LL i=1;i*i<=n;i++)
19      if(n%i==0)
20      {
21                ys[++tot]=i;
22                if(i*i!=n)
23                ys[++tot]=n/i;
24                }
25      sort(ys+1,ys+1+tot);
26      for(int i=1;i<=tot;i++)bh[ys[i]]=i;
27      for(int i=1;i<=tot;i++)
28      for(int j=1;j<=i;j++)
29      if(ys[i]%ys[j]==0)line(i,j);
30 }
31 int dfs(int now,LL dep,int need)
32 {
33     if(ys[now]==1)
34     {
35                   printf("1 ");
36                   return 1;
37                   }
38      if(dep==k)
39      {
40                int us=need;
41                for(int u=head[now];u&&need;need--,u=aft[u])
42                printf("%I64d ",ys[p[u]]);
43                return us-need;
44                }
45      int us=need;
46      for(int u=head[now];u&&need;need-=dfs(p[u],dep+1,need),u=aft[u]);
47      return us-need;
48 }
49 int main()
50 {
51     scanf("%I64d%I64d",&n,&k);if(k>100000)k=100000;
52     init();
53     if(!k)
54     {
55           printf("%I64d\n",n);
56           return 0;
57           }
58     dfs(bh[n],1,100000);
59     return 0;
60 }
View Code

Codeforces Round #256 (Div. 2) E Divisors,布布扣,bubuko.com

Codeforces Round #256 (Div. 2) E Divisors

原文:http://www.cnblogs.com/qscqesze/p/3852510.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!