Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Second Version of Ramanujan's Taxi
- def ramtaxi_O3(n: 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)
- for (c <- a + 1 to n) {
- val c3 = c * c * c
- if (c3 <= n) {
- val d = Math.pow(a3 + b3 - c3, 1.0 / 3.0).toLong
- if (d != a && d != b) {
- val d3 = d * d * d
- if (d3 <= n && a3 + b3 == c3 + d3)
- println(a3 + b3 + " = " + a + "^3 + " + b
- + "^3 = " + c + "^3 + " + d + "^3")
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement