2018_2_2_Heritage_打表_数学

21 篇文章 0 订阅
13 篇文章 0 订阅
Heritage
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7622 Accepted: 2873

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

Source

ural 1108
#include<iostream>  
#include<cstdio>  
#include<algorithm>  
#include<cctype>  
#include<cstring>  
#include<fstream>  
  
using namespace std;  
  
const int N=40000;  
struct bignumber{  
private:  
    int a[N];  
    int len;  
public:  
    bignumber(){  
        memset(a,0,sizeof(a));  
        len=1;   
    }  
    int length(){  
        return len;  
    }  
    int at(int k){  
        if(0<=k&&k<len)return a[k];  
        return -1;  
    }  
    void setnum(char s[]){  
        len=0;
        for(int i=strlen(s)-1;i>=0;i--)
		a[len++]=s[i]-'0';
    }  
    bool iszero(){  
        return len==1&&a[0]==0&&dec==0;  
    }
    void add(bignumber &x){
    	for(int i=0;i<x.len;i++){
    		a[i]+=x.a[i];
			a[i+1]+=a[i]/10;
			a[i]%=10; 
		}
		int k=len;
		while(a[k]){
			a[k+1]+=a[k]/10;
			a[k]%=10;k++;
		}
		len=k; 
	}
	void minus(bignumber &x){
		int i;
		for(i=0;i<x.len;i++){
			a[i]-=x.a[i];
			if(a[i]<0){
				a[i]+=10;
				a[i+1]--;
			}
		}
		if(a[i]<0){
			a[i]+=10;
			a[i+1]--;
		}
		while(!a[len]){
			len--;
		}len++;
	}
    void multiple(bignumber &x){  
        if(x.iszero())setnum("0");  
        int product[N];  
        memset(product,0,sizeof(product));  
        for(int i=0;i<len;i++)  
        for(int j=0;j<x.length();j++)  
        product[i+j]+=a[i]*x.at(j);  
        int k=0;  
        while(k<len+x.length()-1){  
            product[k+1]+=product[k]/10;  
            product[k]%=10;  
            k++;   
        }  
        while(product[k]){  
            product[k+1]+=product[k]/10;  
            product[k]%=10;  
            k++;  
        }  
        len=k;  
        memcpy(a,product,sizeof(product));  
    }
    void print(){
    	//printf("%d\n",len);
    	for(int i=len-1;i>=0;i--)
    	printf("%d",a[i]);
    	puts("");
	}
}a[20];
int n;
bignumber t;
int main(){ 
	t.setnum("1"); 
    a[0].setnum("2");
    for(int i=1;i<=17;i++){
    	a[i]=a[i-1];
    	a[i].multiple(a[i-1]);
    	a[i].add(t);
    	a[i].minus(a[i-1]);
		//printf("%d:",i) ;
		//a[i].print();
	}
    while(scanf("%d",&n)!=EOF){
    	for(int i=0;i<n;i++)
    	a[i].print();
    }  
    return 0;  
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值