Sort by

recency

|

371 Discussions

|

  • + 0 comments
        return (n % M * n % M) %M
    
  • + 0 comments

    It is just binpow(n, 2, mod) for c++

  • + 0 comments

    golang solution

    func summingSeries(n int64) int32 {
        mod := int64(1000000007)
        
        return int32(((n % mod) * (n % mod)) % mod)
    }
    
  • + 0 comments

    python

    def summingSeries(n):
        return n**2 % (10**9+7)
    
  • + 0 comments

    in c++:

    const int MOD = 1000000007;
    
    // Function to perform modular exponentiation
    long long modPow(long long base, long long exp, int mod) {
        long long result = 1;
        base = base % mod;
        while (exp > 0) {
            if (exp & 1) {
                result = (result * base) % mod;
            }
            exp >>= 1;
            base = (base * base) % mod;
        }
        return result;
    }
    
    // Function to calculate the sum of the series
    int summingSeries(long n) {
        long long result = modPow(n, 2, MOD);
        return result;
    }