最大公约数&& 求最小公倍数&&结尾0的个数&&结尾非零数的奇偶性&&光棍

最大公约数

在这里插入图片描述

a=3
b=5
m=list()
n=list()
for i in range(1,a):
    if a%i==0:
        m.append(i)
for j in m:
    if b%j==0:
        n.append(j)
n.sort()
print(n[-1])

求最小公倍数

a=9
b=18
m=list()
n=list()
for i in range(1,a):
    if a%i==0:
        m.append(i)
for j in m:
    if b%j==0:
        n.append(j)
n.sort()
if a%b==0:
    n.append(b)
if b%a==0:
    n.append(a)
product=1
for i in n:
    if i==1:
        continue
    while a%i==0 and b%i==0:
        a=a/i
        b=b/i
        product=product*i
product=product*a*b
print(product)

这个办法好笨

结尾0的个数

在这里插入图片描述

L=[2,8,3,50]
the2=0
the5=0
for i in L:
    while i%2==0:
        the2=the2+1
        i=i/2
    while i%5==0:
        the5=the5+1
        i=i/5
the0=0
if the2>=the5:
    the0=the5
else:
    the0=the2
print(the0)

结尾非零数的奇偶性

在这里插入图片描述

L=[2,8,3,50]
tail=1
for i in L:
    tail=tail*i
    while(tail%10==0):
        tail=tail/10
    if tail>=10:
        tail=tail%10
if tail%2==0:
    print(0)
if tail%2==1:
    print(1)

刚开始读题读错了 结尾非零数意思是:如果最后一位是0而倒数第二位不是0,那么就是用倒数第二位数来比较。。

光棍

在这里插入图片描述
在这里插入图片描述
这里有个错误就是 之前直接给的t=t/2,没有考虑到py好像不是默认的int,于是加了个强制转换就解决了。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值