You are on page 1of 1

(1)(2)+(2)(3)+(3)(4)+⋯+(n)(n+1)=(n)(n+1)(n+2)/3

S=2+4+..+(2n)= n*(n+1)

S=1*2-2*3+3*4-...±n*(n+1)= S=k*(k+1)*-2 .

n=2k=> k=n/2

1. ( a + b) % c = ( ( a % c ) + ( b % c ) ) % c
2. ( a * b) % c = ( ( a % c ) * ( b % c ) ) % c
3. ( a – b) % c = ( ( a % c ) – ( b % c ) ) % c

unsigned long long factorial(int n)


{
    const unsigned int M = 1000000007;
  
    unsigned long long f = 1;
    for (int i = 1; i <= n; i++)
        f = (f*i) % M;  // Now f never can
                        // exceed 10^9+7
    return f;
}

Note: In most of the programming languages (like in C/C++) when you perform modular
operation with negative numbers it gives negative result like -5%3 = -2, but what the
result comes after modular operation should be in the range 0 to n-1 means the -5%3 =
1. So for this convert it into positive modular equivalent.

int mod(int a, int m)


{
    return (a%m + m) % m;
}

You might also like