Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这题要先把除数除尽(欧几里德定理),除尽后再乘,不用int64

Posted by smargo at 2010-04-05 20:13:31 on Problem 2249
大家可以看看,先把分子分母求出来,c(k)(n),然后对每个分母里的因子对分子求最大公约数,最后把所有分母变了1时,再把结果乘出来,就可以了。一次AC
#include "stdio.h"
int gcd(int a,int b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}
int main()
{
	int n,k;
	while(1)
	{
		scanf("%d %d",&n,&k);
		if(n==0&&k==0)
			break;
		if(k==0)
			printf("1\n");
		else
		{
			if(n-k<k)
				k=n-k;
			int* down=new int[k];
			for(int i=0;i<k;i++)
				down[i]=k-i;
			int* up=new int[k];
			for(int i=0;i<k;i++)
				up[i]=n-i;
			for(int i=0;i<k;i++)
			{
				while(1)
				{
					if(down[i]==1)
						break;
					else
					{
						for(int j=0;j<k;j++)
						{
							int g=gcd(up[j],down[i]);
							if(g!=1)
							{
								up[j]/=g;
								down[i]/=g;
								if(down[i]==1)
									break;
							}
						}
					}
				}
			}
			int result=1;
			for(int i=0;i<k;i++)
				result*=up[i];
			printf("%d\n",result);
		}
	}
	return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator