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 dd50900

Browse files
committed
Problem 9
1 parent 251f526 commit dd50900

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 MAXN = 3000
12+
val pyths = for {
13+
s <- 1 to MAXN
14+
t <- s to MAXN
15+
r = math.sqrt(2 * s * t).toInt
16+
if r*r == 2 * s * t
17+
a = r + s
18+
b = r + t
19+
c = r + s + t
20+
sum = a + b + c
21+
product = a * b * c
22+
} /* do */
23+
yield (sum, product)
24+
25+
val answer = pyths.groupBy(_._1) mapValues (seq => (seq map (_._2)).max)
26+
27+
val testCount = nextInt
28+
for (test <- 1 to testCount) {
29+
val N = nextInt
30+
println(answer.getOrElse(N, -1))
31+
}
32+
}
33+
}

0 commit comments

Comments
(0)

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