zoukankan      html  css  js  c++  java
  • 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 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 
     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);
    56           return 0;
    57           }
    58     dfs(bh[n],1,100000);
    59     return 0;
    60 }
    View Code
  • 相关阅读:
    三部曲搭建本地nuget服务器(图文版)
    用批处理编译*.sln工程
    一组无序的整数找出出现次数大于一半的数字
    程序打怪升级之旅
    web开发有那些牛逼东西可以用
    Visual Studio for mac从入门到放弃1
    svn自动更新服务器最新代码
    WinRT支持GB2312
    初试Node —— node.js的安装
    为什么要重写equals方法和hashcode方法
  • 原文地址:https://www.cnblogs.com/qscqesze/p/3852510.html
Copyright © 2011-2022 走看看