给你一个正整数列表 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)