Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a9b23ce

Browse files
committed
Problem 6
1 parent f06ba15 commit a9b23ce

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
object Solution {
2+
3+
val in = {
4+
val lines = scala.io.Source.stdin.getLines
5+
lines flatMap (_ split ' ' filter (_.nonEmpty))
6+
}
7+
8+
def nextInt = in.next.toInt
9+
10+
def main(args: Array[String]): Unit = {
11+
val testCount = nextInt
12+
13+
val MAXN = 10000
14+
def square(x: Long) = x * x
15+
val nums = 1L to MAXN
16+
17+
val sumOfSquares = (nums map square).scanLeft(0L)(_ + _)
18+
val squareOfSum = nums.scanLeft(0L)(_ + _) map square
19+
20+
for (test <- 1 to testCount) {
21+
val N = nextInt
22+
println(squareOfSum(N) - sumOfSquares(N))
23+
}
24+
}
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /