is no problem originally, but the n and m you input here are too large, and the integer overflows, causing i * i to become 0 after overflow, and a division-by-zero exception in the denominator occurs.
1/(i*i) is the division of two integers (in this case, 1/3 is not equal to 0.3333... but equal to 0), I think you need to use 1.0/(i*i) for this. Since i*i may indeed be 0, you'd better judge ahead of time.
is no problem originally, but the
n
andm
you input here are too large, and the integer overflows, causingi * i
to become0
after overflow, and a division-by-zero exception in the denominator occurs.1/(i*i)
is the division of two integers (in this case, 1/3 is not equal to 0.3333... but equal to 0), I think you need to use1.0/(i*i)
for this. Sincei*i
may indeed be 0, you'd better judge ahead of time.