Error404 Blog


Main Page


Segmented Sieve

Use When we have to generate large number of prime Numbers Click Here!


Bithacks

Click Here!


Useful nCr Property

divide by their gcd's to prevent overflow


Useful nCr Property

Find Area of triangle using Side length Heron's Formula.

Area = √(P(P−A)(P−B)(P−C) ) where P is semi perimeter


Cool Mod Formula

(ab)%p = ((a%p)*(b%p))%p Use this to compute large modulos like a^n


Mod properties


Comparing double values


GCD PROPERTIES

gcd(a,b)=gcd(a,b%a) Let X=gcd(a,b) then gcd(X/a,X/b)=1


GCD PROPERTIES

gcd(a,b)=gcd(a,b%a) Let X=gcd(a,b) then gcd(X/a,X/b)=1


i|j means i divides j (j%i==0)


Number of bits for a number

To find number of bits required to represent a number : $$ \lfloor {\log_2{n}} \rfloor + 1$$


Find divisors of a number in $$O( \sqrt {n} )$$


for (int i = 2; i * 1ll * i <= x; ++i) {
    if (x % i == 0) {
        dd.push_back(i);
        if (i != x / i) {
            dd.push_back(x / i);
        }
    }
}
            




Goldbach's Conjecture


Fast nCr

                    
        ll NcR(ll n, ll r) 
        {  
            ll p = 1, k = 1;  
            if (n - r < r) 
                r = n - r; 
        
            if (r != 0) { 
                while (r) { 
                    p *= n; 
                    k *= r; 
                    ll m = __gcd(p, k); 
                    p /= m; 
                    k /= m; 
                    n--; 
                    r--; 
                } 
            } 
        
            else
                p = 1; 

            return p;
        } 
                    
                

Antidifference Function