long long r=N-K<K?(N-K):K;//chose small to miimize the loop
int n=N-(N-r)+1;
r=1;
long long res=1;
for(long long i=n;i<=N;i++)
{
res=res*i;
res=res/r++;
}
cout<<res<<endl;
//-----------------------------------
this is working ...code...

On Sun, Mar 7, 2010 at 3:12 PM, Anil C R <[email protected]> wrote:

> doesn't work for big numbers :P
> Anil
>
>
>
> On Sun, Mar 7, 2010 at 2:53 PM, Rohit Saraf 
> <[email protected]>wrote:
>
>> Here is the code if you want... i have not written it...
>> it's directly copied from wiki :)
>>
>> unsigned long long choose(unsigned n, unsigned k) {
>>     if (k > n)
>>         return 0;
>>
>>     if (k > n/2)
>>
>>
>>
>>
>>         k = n-k; // Take advantage of symmetry
>>
>>     long double accum = 1;
>>     unsigned i;
>>     for (i = 1; i <= k; i++)
>>          accum = accum * (n-k+i) / i;
>>
>>     return accum + 0.5; // avoid rounding error
>>
>>
>>
>>
>> }
>>
>> call choose(n-1,k-1);
>>
>>
>> -Rohit
>>
>>
>>
>> On Sun, Mar 7, 2010 at 2:49 PM, Rohit Saraf 
>> <[email protected]>wrote:
>>
>>> The answer is simply  : (N-1) Choose (k-1)
>>>
>>>
>>> -Rohit
>>>
>>>
>>>
>>> On Sun, Mar 7, 2010 at 2:11 PM, naga vinod kumar <
>>> [email protected]> wrote:
>>>
>>>> How to solve this problem....
>>>>
>>>> http://www.codechef.com/problems/MARBLES/
>>>>
>>>>
>>>> K.Naga Vinod Kumar
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected]<algogeeks%[email protected]>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to