最大公约数
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,于是加了个强制转换就解决了。