legendary_question_six.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 29 June 2019
  4. # https://github.com/trizen
  5. # The problem:
  6. # Let "a" and "b" be positive integers such that a*b + 1 divides a^2 + b^2.
  7. # Show that (a^2 + b^2) / (a*b + 1) is the square of an integer.
  8. # This program presents an efficient method for computing non-trivial solutions to the legendary question six.
  9. # The Legend of Question Six - Numberphile
  10. # https://www.youtube.com/watch?v=Y30VF3cSIYQ
  11. # The Return of the Legend of Question Six - Numberphile
  12. # https://www.youtube.com/watch?v=L0Vj_7Y2-xY
  13. # Solutions for (a^2 + b^2) / (1 + ab) = 4, are given by consecutive values of A052530 = { 2, 8, 30, 112, 418, 1560, 5822, ... }.
  14. # Example:
  15. # ( 2^2 + 8^2) / ( 2*8 + 1) = 4
  16. # ( 8^2 + 30^2) / ( 8*30 + 1) = 4
  17. # ( 30^2 + 112^2) / ( 30*112 + 1) = 4
  18. # (112^2 + 418^2) / (112*418 + 1) = 4
  19. # Similar sequences provide solutions for other values:
  20. # For 3^2: A065100 = { 3, 27, 240, 2133, 18957, 168480, ... }
  21. # For 4^2: A154021 = { 4, 64, 1020, 16256, 259076, 4128960, ... }
  22. # For 5^2: A154022 = { 5, 125, 3120, 77875, 1943755, 48516000, ... }
  23. # For 6^2: A154023 = { 6, 216, 7770, 279504, 10054374, 361677960, ... }
  24. # More generally, let U(n,x) be the Chebyshev polynomials of the second kind, then (a^2 + b^2) / (1 + ab) = m^2, has solutions of the form:
  25. #
  26. # a = m * U(n, m^2 / 2)
  27. # b = m * U(n+1, m^2 / 2)
  28. #
  29. # for any given positive integer m.
  30. use 5.020;
  31. use strict;
  32. use warnings;
  33. use experimental qw(signatures);
  34. use Math::AnyNum qw(:overload chebyshevU);
  35. sub lq6_solutions ($m, $how_many = 5) {
  36. map {
  37. [$m * chebyshevU($_, $m*$m / 2), $m * chebyshevU($_ + 1, $m*$m / 2)]
  38. } 0 .. $how_many-1;
  39. }
  40. foreach my $k (2 .. 10) {
  41. my @S = lq6_solutions($k);
  42. say "(a^2 + b^2) / (1 + ab) = $k^2 has solutions: ", join(', ', map { "[@$_]" } @S);
  43. }
  44. __END__
  45. (a^2 + b^2) / (1 + ab) = 2^2 has solutions: [2 8], [8 30], [30 112], [112 418], [418 1560]
  46. (a^2 + b^2) / (1 + ab) = 3^2 has solutions: [3 27], [27 240], [240 2133], [2133 18957], [18957 168480]
  47. (a^2 + b^2) / (1 + ab) = 4^2 has solutions: [4 64], [64 1020], [1020 16256], [16256 259076], [259076 4128960]
  48. (a^2 + b^2) / (1 + ab) = 5^2 has solutions: [5 125], [125 3120], [3120 77875], [77875 1943755], [1943755 48516000]
  49. (a^2 + b^2) / (1 + ab) = 6^2 has solutions: [6 216], [216 7770], [7770 279504], [279504 10054374], [10054374 361677960]
  50. (a^2 + b^2) / (1 + ab) = 7^2 has solutions: [7 343], [343 16800], [16800 822857], [822857 40303193], [40303193 1974033600]
  51. (a^2 + b^2) / (1 + ab) = 8^2 has solutions: [8 512], [512 32760], [32760 2096128], [2096128 134119432], [134119432 8581547520]
  52. (a^2 + b^2) / (1 + ab) = 9^2 has solutions: [9 729], [729 59040], [59040 4781511], [4781511 387243351], [387243351 31361929920]
  53. (a^2 + b^2) / (1 + ab) = 10^2 has solutions: [10 1000], [1000 99990], [99990 9998000], [9998000 999700010], [999700010 99960003000]