For comparison:
>> val x = 1 to Int.MaxValue x: scala.collection.immutable.Range.Inclusive with scala.collection.immutable.Range.ByOne = Range(...)
WITH
>> val x = 1L to Int.MaxValue x: scala.collection.immutable.NumericRange.Inclusive[Long] = NumericRange(...)
Note that the former uses Int.to , and the latter used Long.to (where Int.MaxValue is converted automatically). Of course, the sum of a sequential integer sequence has a very good discrete formula :)
Happy coding.
user166390
source share