Re: [algogeeks] Re: Modular arithmetic + Combinatorics

2012-01-04 Thread atul anand
@Dave : in your pseudo code for B(m,n) you are not using m ... i guess there is a typo error. this should be num[i]=m + 1 -i instead of this num[i] = n + 1 - i -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send emai

Re: Re: Re: [algogeeks] Re: Modular arithmetic + Combinatorics

2011-11-05 Thread mohit verma
@ myself Dave's solution works fine. I should have close look at it. On Sat, Nov 5, 2011 at 12:17 PM, mohit verma wrote: > @ Dave > > I think your solution wont work for the cases like (MAX_INT) C > (MAX_INT-1). > > > On Thu, Nov 3, 2011 at 10:20 PM, wrote: > >> correction: "if P is prime" >>

Re: Re: Re: [algogeeks] Re: Modular arithmetic + Combinatorics

2011-11-05 Thread mohit verma
@ Dave I think your solution wont work for the cases like (MAX_INT) C (MAX_INT-1). On Thu, Nov 3, 2011 at 10:20 PM, wrote: > correction: "if P is prime" > > VM > NSIT, Dwarka > > > On , vaibhavmitta...@gmail.com wrote: > > Use Lucas Theorem is P is prime. > > > > VM > > NSIT, Dwarka > > > > O

Re: Re: Re: [algogeeks] Re: Modular arithmetic + Combinatorics

2011-11-03 Thread vaibhavmittal11
correction: "if P is prime" VM NSIT, Dwarka On , vaibhavmitta...@gmail.com wrote: Use Lucas Theorem is P is prime. VM NSIT, Dwarka On , Dipit Grover dipitgro...@gmail.com> wrote: > Thats really cool! Thanks Dave :) > > > > > -- > > You received this message because you are subscribed to t

Re: Re: [algogeeks] Re: Modular arithmetic + Combinatorics

2011-11-03 Thread vaibhavmittal11
Use Lucas Theorem is P is prime. VM NSIT, Dwarka On , Dipit Grover wrote: Thats really cool! Thanks Dave :) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To u

Re: [algogeeks] Re: Modular arithmetic + Combinatorics

2011-11-02 Thread Dipit Grover
Thats really cool! Thanks Dave :) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more

[algogeeks] Re: Modular arithmetic + Combinatorics

2011-11-02 Thread Dave
@Dipit: Here's how you would do it by hand: B(1000,10) = 1000*999*998*997*996*995*994*993*992*991 / (1*2*3*4*5*6*7*8*9*10). We know that the result is an integer, so all of the terms in the denominator are factors of the numerator. Do some cancelling: 10 cancels 1000 to 100, 9 cancels 999 to 111, 8

Re: [algogeeks] Re: Modular arithmetic

2011-10-29 Thread mohit verma
You can do something like this: ( n* alpha) * ( m*alpha) *p where 0 wrote: > > > On Sat, Oct 22, 2011 at 9:04 PM, Mad Coder wrote: > >> >> >> Can anyone explain why ((n%p)*(m%p))%p will give wrong answer ? >> >> Lets say, n = 10^15 , m = 10^15 and p = 10^18 > > So, > n%p = 10^15

Re: [algogeeks] Re: Modular arithmetic

2011-10-22 Thread Aamir Khan
On Sat, Oct 22, 2011 at 9:04 PM, Mad Coder wrote: > > > Can anyone explain why ((n%p)*(m%p))%p will give wrong answer ? > > Lets say, n = 10^15 , m = 10^15 and p = 10^18 So, n%p = 10^15 m%p = 10^15 And the intermediate result (n%p)*(m%p) will overflow the long long range. > -- > You receive

Re: [algogeeks] Re: Modular arithmetic

2011-10-22 Thread Mad Coder
Can anyone explain why ((n%p)*(m%p))%p will give wrong answer ? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr

[algogeeks] Re: Modular arithmetic

2011-10-21 Thread Dave
@Aamir: Something like this might work: n %= p; m %= p; result = 0; while( m ) { if( m & 1 ) { result += n; if( result >= p ) result -= p; } m >>= 1; n <<= 1; if( n >= p ) n -= p; } What this does is similar to the elementary school meth

[algogeeks] Re: Modular arithmetic

2011-10-21 Thread Don
Use NTL's ZZ extended integer type. Don On Oct 21, 12:26 pm, Aamir Khan wrote: > Lets say n,m and p are three long long integers. > > i want to calculate (n*m)%p. > > If (n*m) overflows the limit of long long then the answer would be wrong. > Moreover if i do ((n%p)*(m%p))%p then also there is no

Re: [algogeeks] Re: Modular Arithmetic

2011-01-13 Thread Nikhil Jindal
On Thu, Jan 13, 2011 at 12:06 AM, Aviral Gupta wrote: > we can do it when hcf(b,m)=1 , in that case find inverse of b by > extended euclidean mod m and then multiply it by a > Yes. And when m is prime, B(mulitplicative inverse of b) = b^(m-2) As b^(m-1)mod m = 1 if m is prime. > > Regards > Avir

[algogeeks] Re: Modular Arithmetic

2011-01-12 Thread Aviral Gupta
we can do it when hcf(b,m)=1 , in that case find inverse of b by extended euclidean mod m and then multiply it by a Regards Aviral http://coders-stop.blogspot.com/ On Jan 12, 6:36 am, mittal wrote: > Somehelp with (a/b)modm expression. > > http://en.wikipedia.org/wiki/Modular_arithmetic > i visi