📜  Python| sympy.trailing() 方法

📅  最后修改于: 2022-05-13 01:54:37.732000             🧑  作者: Mango

Python| sympy.trailing() 方法

sympy.trailing()方法的帮助下,我们可以计算给定数字的二进制表示中尾随零位的数量,即确定除以该数字的 2 的最大幂。

示例 #1:

# import trailing() method from sympy
from sympy.ntheory.factor_ import trailing
   
n = 64
   
# Use trailing() method 
trailing_n = trailing(n) 
       
print("The largest power of 2 that divides {} is 2^{}.".
      format(n, trailing_n))

输出:

The largest power of 2 that divides 64 is 2^6.

示例 #2:

# import trailing() method from sympy
from sympy.ntheory.factor_ import trailing
  
n = 130
  
# Use trailing() method 
trailing_n = trailing(n) 
      
print("The largest power of 2 that divides {} is 2^{}.".
      format(n, trailing_n))

输出:

The largest power of 2 that divides 130 is 2^1.