E. Divisors
Bizon the champion isn't just friendly, he also is a rigorous coder.
Let's define functionF(A), WhereAIs a sequence of integers. FunctionF(A) Returns the following sequence: First all divisorsA1 go in the increasing order, then all divisorsA2 go in the increasing order, and so on till the last element of SequenceA. For example,F([2, 9, 1_1]) records = values [1, 1_2, 1_1, 1_3, 1_9, 1_1].
Let's determine the sequenceXI, For integerI(ILimit ≥ limit 0 ):X0 bytes = average [X] ([X] Is a sequence consisting of a single numberX),XISignature = SignatureF(XIHistogram-interval 1 )(ILatency> limit 0). For example,XKeys = keys 6 we getX0 bytes = bytes [6],X1 rows = Second [1, second 2, second 3, second 6],X2 records = records [1, records 1, records 2, records 1, records 3, records 1, records 2, records 3, records 6].
Given the numbersXAndK, Find the sequenceXK. 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 digit ≤ DigitXLimit ≤ limit 1012) andK(0 bytes ≤ bytesKLimit ≤ limit 1018 ).
Output
Print the elements of the sequenceXKIn 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",n);56 return 0;57 }58 dfs(bh[n],1,100000);59 return 0;60 }
View code