Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Third Version of Ramanujan's Taxi
- def ramtaxi_O2(n: Long) = {
- val mapSums = mutable.HashMap.empty[Long, List[(Long, Long)]]
- var overOne = mutable.SortedSet[Long]()
- for (a <- 1L to n) {
- val a3 = a * a * a
- if (a3 <= n)
- for (b <- a to n) {
- val b3 = b * b * b
- if (b3 <= n) {
- val ab3 = a3 + b3
- mapSums += (ab3 -> ((a3, b3)
- :: mapSums.getOrElse(ab3, List())))
- if (mapSums(ab3).length > 1)
- overOne += ab3
- }
- }
- }
- overOne foreach {x => println(x + " = " + mapSums(x))}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement