TOJ 2969.HELP ! ! !

题目链接:http://acm.tju.edu.cn/toj/showp2969.html


2969.    HELP ! ! !
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 1436    Accepted Runs: 434



Sojib is a student of class VI. He just learned the algebraic equation (a+b)^2. 
    (a+b)^2 = (a+b)*(a+b)
            = a*a+a*b+a*b+b*b
            = a^2+2*a*b+b^2
After sometimes he thought, if I could solve it for (a+b)^3. So he starts with the same way as he did it for (a+b)^2. After performing the calculation he has found that the coefficient for (a+b)^3 are 1, 3, 3, 1. Here the order is taken as the decreasing order of the power of a . Now he thinks if I could solve it for higher terms of the power of (a+b). But he felt bored after sometimes as so much multiplication has to perform. But he is very much interested to know what will be the sequence of co-efficient if it arranged for decreasing order of the power of a. He heard that a programming contest is arranged for 05 batch of CUET. He knows all of the students of 05 are good at programming. So he asked you, if you can help him by telling him the sequence of coefficients in decresing order of the power of a. 

Input

Input consists of one integer n (0≤n≤50) that represents the power of (a+b). Input will be terminated by a negative number. 

Output

For each number just print the sequence of co-efficients in decreasing order of the power of a. There will be a space in between every number in the sequence. 

Sample Input

3
7
-1

Sample Output

1 3 3 1
1 7 21 35 35 21 7 1

Problem Setter : John



Source: CUET Easy Contest
Submit   List    Runs   Forum   Statistics

水题,但是错了好多次,这个题有点j,也是由于粗心,以为只要用n!=0来确保输入结束就可以了,没有考虑错误的输入,类似n=-2等,最后才发现改成n>=0才对。主要是题目说了n的范围,所以也没多想。。。


#include <stdio.h>
int main(){
	long long a[51];
	int n;
	double tmp;
	while(scanf("%d",&n) &&n>=0){
		a[0]=a[n]=1;
		for(int i=1;i<=n/2;i++){
			tmp=1.0;
			for(int j=0;j<i;j++)
				tmp*=(double)(n-j)/double(i-j);
			a[i]=a[n-i]=tmp+0.5;
		}
		for(int i=0;i<n;i++)
			printf("%lld ",a[i]);
		printf("%lld\n",a[n]);
	}
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值