题解 | #质数因子#

质数因子

https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607

# a=int(input())

# def sub(num):
#     if num%2==0:
#         return 2,num/2
#     else:
#         m=int(num/2)
#         i=1
#         while  2**i+1<=m:
#             if  num%(2**i+1)==0:
#                 return 2**i+1,num/(2**i+1)
#             i=i+1
#     return 0,num

# s_list=[]
# s1,s2=sub(a)
# while s1!=0:
#     s_list.append(s1)
#     s1,s2=sub(s2)
# if s2>1:
#     s_list.append(int(s2))

# print(' '.join(str(s) for s in s_list))


a = int(input())

def sub(num):
    if num % 2 == 0:
        return 2, num // 2
    else:
        i = 1
        while (2 * i + 1)*2 * i + 1 <= num:
            if num % (2 * i + 1) == 0:
                return 2 * i + 1, num // (2 * i + 1)
            i = i + 1
    return 0, num

s_list = ''
s1, s2 = sub(a)
while s1 != 0:
    s_list+=str(s1)+' '
    s1, s2 = sub(s2)
if s2 > 1:
    s_list+=str(s2)+' '

print(s_list)

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务