Part of the series

Several example codes

~1 min read • Updated Oct 13, 2025

Program Overview

This Python program reads an integer n and computes the result of the following series:
∑ [log(k^(k-1) / (k^k - 1))] for k from 2 to n
It uses math.log for natural logarithm calculations.


Python Code:


import math

def compute_log_series(n: int) -> float:
    total = 0.0
    for k in range(2, n + 1):
        numerator = k ** (k - 1)
        denominator = k ** k - 1
        term = math.log(numerator / denominator)
        total += term
    return total

# Read input from user
n = int(input("Enter value for n: "))
result = compute_log_series(n)
print(f"Series result is: {result:.6f}")

Sample Output (input: n = 4):


Series result is: -1.191274

Written & researched by Dr. Shahin Siami