python实现 1044 Shopping in Mars (25)


x=int(input())

def isPrime(n):        #目的返回第一个能够整除的数   使用的素数筛选法的思想
  i = 3
  while i * i <= n:
    if n % i == 0:
      return i
    i += 2
  return n

if x%2==0:           #分为奇数偶数分别处理   奇数和素数只有一个除数,而偶数存在多个
    if x==2:
        print(1)
        print(x)
    else:
        first=x              #第一个因数
        maxcount=0           #最多有几个连续的因数
        for i in range(2,x):
            count=0
            start=i
            tmp=x
            while tmp%start==0:  #开始判断有几个连续的因数
                count+=1
                tmp=tmp//start
                start+=1
            if start-i>maxcount:
                maxcount=start-i
                first=i
        print(maxcount)
        res=[first]*maxcount
        for i in range(1,maxcount):
            res[i]=res[i]+i
        print("*".join([str(i) for i in res]))



else:
    print(1)
    print(isPrime(x))

其他方面参考这篇博文

https://blog.csdn.net/jmlikun/article/details/49968399

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值