python【蓝桥杯vip练习题库】ADV-69质因数(数论)

试题 算法提高 质因数

资源限制
时间限制:1.0s 内存限制:512.0MB
  将一个正整数N(1<N<32768)分解质因数。例如,输入90,打印出90=2335。
样例输入
66
样例输出
66=2
3*11


"""
@Author:Lixiang

@Blog(个人博客地址): https://lixiang007.top/

@WeChat:18845312866

"""
import math
import string
import sys
import cmath
from itertools import permutations
def fun(n,res):
    for i in range(2,n+1):
        if n %i==0:
            res+=str(i)
            n=n//i
            if n==1:#短除到质数退出
                return res
            else:
                res+='*'
                return fun(n,res)
n=int(input())
res=""
temp=fun(n,res)
print(n,"=",temp,sep="")

在这里插入图片描述

发布了829 篇原创文章 · 获赞 215 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/weixin_43838785/article/details/104679905
今日推荐