DaysGone's blog

By DaysGone, history, 4 years ago, In English

Hello Codeforces

Can u plzz tell me an effective way to convert any decimal floating point number (either double) to an p/q (rational form) where gcd(p,q) = 1 ?? And remember that we have number given up to _6 accurate places_ after decimal point.

Read more »

 
 
 
 
  • Vote: I like it
  • -5
  • Vote: I do not like it

By DaysGone, history, 4 years ago, In English

Hello everyone i just came over to this problem somewhere that if i have two very very large numbers (10^9) and i want to multiply under some modulo mod...

then we have snippet like this works :

ll mulmod(ll a, ll b, ll mod)
{
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0)
    {
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;
 
        // Multiply 'a' with 2
        a = (a * 2) % mod;
 
        // Divide b by 2
        b /= 2;
    }
 
    // Return result
    return res % mod;
}

But how to handle this when b is large negative number of the order (-10^9).. plzz help thanks

Read more »

 
 
 
 
  • Vote: I like it
  • -6
  • Vote: I do not like it