Squaring the reciprocal sequence and a portion (15 minutes)

Chapter 2-11 squaring the reciprocal portion and the sequence (15 minutes)

This problem requires two positive integers m and n (m≤n) programming, and calculates the sequence m
2. 1 + / m + (. 1 + m) 2 +. 1 / (m +. 1) + ⋯ + n- 2 + 1 / n.

Input formats:

Input given two positive integers m and n (m≤n) in a row, separated by spaces therebetween.

Output formats:

And output portion of the value S in accordance with the "sum = S" format in a row, six decimal place. Title ensure that the calculation result does not exceed the double precision.

Sample input:

5 10

Sample output:

sum = 355.845635
a,b = map(int,input().split())
print("sum = %.6f"%(sum([i**2+1/i for i in range(a,b+1)])))

Guess you like

Origin www.cnblogs.com/nonlinearthink/p/10991521.html
Recommended