Heritage
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7296 | Accepted: 2714 |
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.
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
Source
题意:遗产总量为1,n个继承人,第i人获得1/ai,1/ai随i增加而减少,要求分给n个人后必须有剩余,而且要求剩余最少。
分析:高精度,用java做
我们认为最开始财产是1/1
我们对于财产剩余1/a时,应分给当前继承人1/(a+1)的财产。然后财产还剩下1/(a * (a + 1))。按此递推
import java.util.*;
import java.math.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner (System.in);
BigInteger a;
int n;
a = BigInteger.valueOf(1);
n=in.nextInt();
for(int i=1;i<=n;i++)
{
System.out.println(a.add(BigInteger.valueOf(1)));a = a.multiply(a.add(BigInteger.valueOf(1)));
}
}
}