Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Hangdian ACm, problem1001’s question, why can’t the Gaussian algorithm be used?
Hangdian ACm, problem1001’s question, why can’t the Gaussian algorithm be used?

Because when n is very large, the value of n*(n+1) will overflow. You can judge whether it is odd or accidental and then do the division first.

Note this sentence: You may assume the result will be in the range of 32-bit signed integer.

The requirement is that your result will be in the range of 32-bit signed integer. . Assume that the result of n*(n+1)/2 just meets 32 bits. But before doing the division

the result of n*(n+1) exceeds 32 bits.