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

long long 完破~

Posted by porker2008 at 2011-09-14 02:25:01 on Problem 1942
#include <iostream>
using namespace std;

long long gcd(long long a, long long b)
{
	long long m = a>b?a:b;
	long long n = a>b?b:a;
	if(n==0) return m;
	else if(m%n==0) return n;
	else return gcd(n,m%n);
}

long long C(long long m, long long sum)
{
	long long result = 1;
	if(m<sum-m) m = sum - m;
	for(long long i = sum;i>=m+1;i--)
	{
		long long temp = gcd(i,sum-i+1);
		result /= (sum-i+1) / temp;
		result *= i/temp;
	}
	return result;
}

int main()
{
	long long m,n;
	while(1)
	{
		cin >> m >> n;
		if(m==0 && n==0) break;
		cout << C(m,m+n) << endl;
	}
}

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