POJ1405Heritage大树相乘

来源:互联网 发布:java设计工程师学习 编辑:程序博客网 时间:2024/05/01 07:19
H - Heritage
Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u
SubmitStatus

Description

Your rich uncle died recently, and the heritage needs to be divided among your relatives and the church (your uncle insisted in his will that the church must get something). There are N relatives (N <= 18) that were mentioned in the will. They are sorted in descending order according to their importance (the first one is the most important). Since you are the computer scientist in the family, your relatives asked you to help them. They need help, because there are some blanks in the will left to be filled. Here is how the will looks:

Relative #1 will get 1 / ... of the whole heritage,
Relative #2 will get 1 / ... of the whole heritage,
---------------------- ...
Relative #n will get 1 / ... of the whole heritage.

The logical desire of the relatives is to fill the blanks in such way that the uncle's will is preserved (i.e the fractions are non-ascending and the church gets something) and the amount of heritage left for the church is minimized.

Input

The only line of input contains the single integer N (1 <= N <= 18).

Output

Output the numbers that the blanks need to be filled (on separate lines), so that the heritage left for the church is minimized.

Sample Input

2

Sample Output

2

3

<pre name="code" class="cpp">#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){    //数组a储存an-1,数组sum存在an    int i,j,k,p,m,N,a[50000]= {0},sum[50000]= {0};    scanf("%d",&N);    a[0]=2;    printf("2\n");    for(i=1,m=1; i<N; i++)    {        for(j=0; j<m; j++)        {            for(k=0; k<m; k++)            {                if(k==0)//k=0时即是个位数,要减1,代表(an-1 - 1)                    sum[j+k]+=a[j]*(a[k]-1);                else                    sum[j+k]+=a[j]*a[k];            }        }        m=j+k;//求和之后的和的最大位数        sum[0]+=1;        for(j=0; j<m; j++)//进位        {            if(sum[j]>9)            {                sum[j+1]+=sum[j]/10;                sum[j]%=10;            }            a[j]=sum[j];//把结果赋给a[j],继续上述循环过程        }        for(k=m; sum[k]==0; k--);        m=k+1;//缺失了不AC        for(j=k; j>=0; j--)        {            printf("%d",sum[j]);            sum[j]=0;//清除每次sum[j]带来的影响        }        printf("\n");    }    return 0;}

这个数列的前几项如下:


2


3


7


43


1807


3263443


10650056950807


113423713055421844361000443


12864938683278671740537145998360961546653259485195807


165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443


通项:a[i]=2(i=0)

a[i]=a[i-1]*(a[i-1]-1)+1;

0 0
原创粉丝点击