You can do something like this:

        ( n* alpha)  * ( m*alpha) *p

where     0<alpha<1  which maps product onto (0,1) interval. You can use
golden ration instead.

On Sat, Oct 22, 2011 at 9:45 PM, Aamir Khan <[email protected]> wrote:

>
>
> On Sat, Oct 22, 2011 at 9:04 PM, Mad Coder <[email protected]> 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 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.
>>
>
>
>
> --
> Aamir Khan | 3rd Year  | Computer Science & Engineering | IIT Roorkee
>
>
>  --
> 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.
>



-- 
Mohit

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