Summing the K-N-R Series

  • + 0 comments

    Solving the K-N-R problem not only reflects technical ability but also reinforces resilience and determination in overcoming challenges. Just like in a career transition, problem-solving requires patience, strategy, and the precise application of skills. Every step, whether in solving a problem or building a career, contributes to a more solid and rewarding journey when well-guided.

    include

    include

    include

    include

    define MOD 1000000007

    // Function to calculate modular exponentiation long long mod_exp(long long base, long long exp, long long mod) { long long result = 1; while (exp > 0) { if (exp % 2 == 1) { result = (result * base) % mod; } base = (base * base) % mod; exp /= 2; } return result; }

    int main() { int T; scanf("%d", &T);

    while (T--) {
        long long K, n, R;
        scanf("%lld %lld %lld", &K, &n, &R);
    
        long long Sn = 0;
    
        for (long long i = 1; i <= n; i++) {
            long long term = mod_exp(i, K, MOD) * mod_exp(R, i, MOD) % MOD;
            Sn = (Sn + term) % MOD;
        }
    
        printf("%lld\n", Sn);
    }
    
    return 0;
    

    }