Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // Second Version of Ramanujan's Taxi
  2. def ramtaxi_O3(n: Long) = {
  3. for (a <- 1L to n) {
  4. val a3 = a * a * a
  5. if (a3 <= n)
  6. for (b <- a to n) {
  7. val b3 = b * b * b
  8. if (b3 <= n)
  9. for (c <- a + 1 to n) {
  10. val c3 = c * c * c
  11. if (c3 <= n) {
  12. val d = Math.pow(a3 + b3 - c3, 1.0 / 3.0).toLong
  13. if (d != a && d != b) {
  14. val d3 = d * d * d
  15. if (d3 <= n && a3 + b3 == c3 + d3)
  16. println(a3 + b3 + " = " + a + "^3 + " + b
  17. + "^3 = " + c + "^3 + " + d + "^3")
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement