lcm

paddle. lcm ( x, y, name=None ) [source]

Computes the element-wise least common multiple (LCM) of input |x| and |y|. Both x and y must have integer types.

Note

lcm(0,0)=0, lcm(0, y)=0

If x.shape != y.shape, they must be broadcastable to a common shape (which becomes the shape of the output).

Parameters
  • x (Tensor) – An N-D Tensor, the data type is int32, int64.

  • y (Tensor) – An N-D Tensor, the data type is int32, int64.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

An N-D Tensor, the data type is the same with input.

Return type

out (Tensor)

Examples

>>> import paddle

>>> x1 = paddle.to_tensor(12)
>>> x2 = paddle.to_tensor(20)
>>> paddle.lcm(x1, x2)
Tensor(shape=[], dtype=int64, place=Place(cpu), stop_gradient=True,
60)

>>> x3 = paddle.arange(6)
>>> paddle.lcm(x3, x2)
Tensor(shape=[6], dtype=int64, place=Place(cpu), stop_gradient=True,
[0, 20, 20, 60, 20, 20])

>>> x4 = paddle.to_tensor(0)
>>> paddle.lcm(x4, x2)
Tensor(shape=[], dtype=int64, place=Place(cpu), stop_gradient=True,
0)

>>> paddle.lcm(x4, x4)
Tensor(shape=[], dtype=int64, place=Place(cpu), stop_gradient=True,
0)

>>> x5 = paddle.to_tensor(-20)
>>> paddle.lcm(x1, x5)
Tensor(shape=[], dtype=int64, place=Place(cpu), stop_gradient=True,
60)