code: private static long lcm(long x, long y) {
          // binary gcd algorithm from Knuth, "The Art of Computer Programming,"
          // vol. 2, 1st ed., pp. 298-299
          long x1 = x;
          long y1 = y;
  
          int p2 = 0;
          while ((x1 & 1) == 0 && (y1 & 1) == 0) {
              ++p2;
              x1 >>= 1;
              y1 >>= 1;
          }
  
          long t;
          if ((x1 & 1) == 1) {
              t = -y1;
          } else {
              t = x1;
          }
  
          while (t != 0) {
              while ((t & 1) == 0) {
                  t >>= 1;
              }
              if (t > 0) {
                  x1 = t;
              } else {
                  y1 = -t;
              }
              t = x1 - y1;
          }
          long gcd = x1 << p2;
  
          // x * y == gcd(x, y) * lcm(x, y)
          return x / gcd * y;
      }
docs: Calculates the least common multiple of x and y.