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 af8016a

Browse files
committed
Problem 2
1 parent 603cec9 commit af8016a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import scala.io.Source
2+
3+
object Solution {
4+
val in = {
5+
val lines = Source.stdin.getLines
6+
lines flatMap (_ split ' ' filter (_.nonEmpty))
7+
}
8+
9+
def nextInt = in.next.toInt
10+
def nextLong = in.next.toLong
11+
12+
val fibs: Stream[Long] = 1L #:: fibs.scanLeft(2L)(_ + _)
13+
14+
def main(args: Array[String]): Unit = {
15+
val testCount = nextInt
16+
for (test <- 1 to testCount) {
17+
val N = nextLong
18+
val evenFibs = fibs takeWhile (_ <= N) filter (_ % 2 == 0)
19+
println(evenFibs.sum)
20+
}
21+
}
22+
}

0 commit comments

Comments
(0)

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