## ACM刷题之-POJ-1405(Heritage)

# 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

# 我的答案

```
import java.io.*;
import java.math.*;
import java.util.*;
class Main
{
public static void main(String[] args)
{
BigInteger[] answer = new BigInteger[18];
BigInteger temp = BigInteger.valueOf(2);;
answer[0] = BigInteger.valueOf(2);
BigInteger one = BigInteger.valueOf(1);
Scanner cin = new Scanner(new BufferedInputStream(System.in));
int n = cin.nextInt();
System.out.println(answer[0]);
for(int i = 1;i < n;i++)
{
answer[i] = temp.add(one);
temp = temp.multiply(answer[i]);
System.out.println(answer[i]);
}
}
}
```

# 微信公众号

# 关于版权和转载

**本文由 潘建锋 创作，采用 署名 4.0 国际 (CC BY 4.0) 国际许可协议进行授权。**

**本站文章除注明转载/出处外，均为本站原创或翻译，转载时请务必署名，否则，本人将保留一切追究责任的权利。**

## 转载规范

标题：ACM刷题之-POJ-1405(Heritage)作者：潘建锋

原文：https://taohuawu.club/POJ-1405