题解 | #小红和小紫的取素因子游戏#(Python3)
小红和小紫的取素因子游戏
https://www.nowcoder.com/practice/6146f391a69547c4804fe8d0330f1745
N = 100100 # b = [False] * N # # 标记素数 # def init(): # b[0] = b[1] = True # for i in range(2, N): # if(not b[i]): # for j in range(i*i, N, i): # b[j] = True # init() # 游戏次数t t = int(input()) for _ in range(0, t): # 要讨论的正整数x x = int(input()) cnt = 0 for k in range(2, N): while(x%k==0): cnt += 1 x /= k if (x!=1): cnt += 1 if (cnt%2==1): print("kou") else: print("yukari")
def solve(): n = int(input()) sum = 0 i = 2 # 一个数 n 最多只会有一个大于根号 n 的“大”因子 # 遍历找到根号n就可以了不用到n while i * i <= n: while n % i == 0: sum += 1 n //= i i += 1 if n > 1: sum += 1 print("kou" if sum % 2 else "yukari") def main(): __t = int(input()) for _ in range(__t): solve() if __name__ == "__main__": main()#15天刷题#