qqz.classical_utils
1import math 2 3def lcm(a, b): 4 """Least common multiple: $\mathrm{lcm}(a,b)$ 5 6 Args: 7 a (int): $a$ 8 b (int): $b$ 9 10 Returns: 11 $\mathrm{lcm}(a,b)$ 12 """ 13 14 return a * b / math.gcd(a, b) 15 16 17def decode_bin(register_bin: str) -> int: 18 """Decode binaries of a register. 19 20 Args: 21 register_bin (str): binaries of the register 22 23 Returns: 24 An integer represented by the given binaries 25 26 Examples: 27 28 ``` 29 >>> decode_bin('011') 30 3 31 ``` 32 """ 33 34 return int(register_bin[-len(register_bin):], 2)
def
lcm(a, b):
4def lcm(a, b): 5 """Least common multiple: $\mathrm{lcm}(a,b)$ 6 7 Args: 8 a (int): $a$ 9 b (int): $b$ 10 11 Returns: 12 $\mathrm{lcm}(a,b)$ 13 """ 14 15 return a * b / math.gcd(a, b)
Least common multiple: $\mathrm{lcm}(a,b)$
Arguments:
- a (int): $a$
- b (int): $b$
Returns:
$\mathrm{lcm}(a,b)$
def
decode_bin(register_bin: str) -> int:
18def decode_bin(register_bin: str) -> int: 19 """Decode binaries of a register. 20 21 Args: 22 register_bin (str): binaries of the register 23 24 Returns: 25 An integer represented by the given binaries 26 27 Examples: 28 29 ``` 30 >>> decode_bin('011') 31 3 32 ``` 33 """ 34 35 return int(register_bin[-len(register_bin):], 2)
Decode binaries of a register.
Arguments:
- register_bin (str): binaries of the register
Returns:
An integer represented by the given binaries
Examples:
>>> decode_bin('011')
3