I got a doubt in the following code:

if (k> n / 2)
k = n-k;
for (i = 1; i <= k, i + +)
ans = ans * (n +1- i) / i;

If (n +1- i) is not divisible by i this code should be wrong?

I thought I needed to keep the numerator and denominator and go by dividing
the numerator and denominator gcd

num = 1
den = 1

for (i = 1; i <= k, i + +) {
    num *= n +1- i;
    den *= i;
    d = gcd (num, den);
    num /=  d;
    den / = d;
}

printf ("% d", num);

Wladimir Araujo Tavares
*Federal University of CearĂ¡

*




On Tue, Jun 21, 2011 at 12:34 PM, PRAMENDRA RATHi rathi <[email protected]
> wrote:

> i have also got AC...i am only asking for best algo.....
>
>
>
>
>
>
> PRAMENDRA RATHI
> NIT ALLAHABAD
>
>
>
>
>  --
> 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.
>

-- 
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