给你一个正整数列表 L, 输出L内所有数字的乘积末尾0的个数;给你两个正整数a,b,  输出它们公约数的个数

给你一个正整数列表 L, 输出L内所有数字的乘积末尾0的个数。(提示:不要直接相乘,数字很多,相乘得到的结果可能会很大)。

例如: L=[2,8,3,50],

则输出:2

解法一

 

L内元素乘积零的个数取决于L内元素%2||%5==0的最小值

print(2*8*5*4*2)
print(8*5*50*5*5*2)
runfile('D:/Python/hoilday_codes/pythontip.py', wdir='D:/Python/hoilday_codes')
640(一个零n%5的个数)
2500(两个零n%2的个数)

L=[2,8,3,50]


import math
global c1
global c2
c1, c2 = 0, 0
for x in L:
    while x%2 == 0:
        x = x / 2
        c1 += 1
    while x%5 == 0:
        x = x / 5
        c2 += 1
print(min(c1,c2))

 

解法二


product,count=1,0

for i in [i for i in L if i%2==0 or i%5==0]:
    product*=i
    while product%10==0:
        product=product//10
        count+=1
print(count)

 

给你一个正整数列表 L, 判断列表内所有数字乘积的最后一个非零数字的奇偶性。如果为奇数输出1,偶数则输出0.。

例如:L=[2,8,3,50]

则输出:0

product,count=1,0
s=1
for j in L:
    s=s*j
for i in [i for i in L if i%2==0 or i%5==0]:
    product*=i
    while product%10==0:
        product=product//10
        count+=1
s=s//10**count

s=s%10

if s%2==0:
    print(0)
else:
    print(1)

 

 

"""
给你两个正整数a,b,  输出它们公约数的个数。
例如:a = 24, b = 36
则输出:6
"""

c=0
a,b=24,36
for i in range(1,min(a,b)+1):
    if a%i==0and b%i==0:
        c=c+1;
print(c)
    


L=[]
for x in range(1,min(a,b)+1):
   if a%x==0:
      if b%x==0:
         L.append(x)
print(len(L))
print(L)
    

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值