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 format:
Input give two positive integers m and n (m≤n) in a row, separated by spaces therebetween.

Output format:
output section and the value S in accordance with the "sum = S" format in a row, accurate to six decimal places. Title ensure that the calculation result does not exceed the double precision.

Sample input:
510

Output Sample:
SUM = 355.845635

m,n=input().split()
m=int(m)
n=int(n)
s=sum(i*i+1/i for i in range(m,n+1))
print("sum = %.6f"%s)
Published 14 original articles · won praise 1 · views 88

Guess you like

Origin blog.csdn.net/weixin_45948920/article/details/104345809