题解 | 因数博弈
因数博弈
https://www.nowcoder.com/practice/f51bc958f8a24537bccaf1e893957056
观察出来的,将这个数进行质因数分解。如果分解出来的数量是2个,例如4=2*2,6=2*3。那么就是Bob获胜,其余情况则是Alice获胜。
def prime_factors(n):
factors = []
x = n
i = 2
while i * i <= x:
while x % i == 0:
factors.append(i)
x //= i
i += 1
if x > 1:
factors.append(x)
return factors
n = int(input())
factors = prime_factors(n)
if len(factors) == 2:
print("Bob")
else:
print("Alice")

阿里云工作强度 667人发布