一組發票共有8個數字,已知某組發票前2個數字可被2整除,前3個數字可被3整除,前4個數字可被4整除,………,全部8個數字可被8整除,每個數字恰出現一次,求此組發票號碼?
Python Code:
import itertools
w=[]
b=[]
for i in range(1,9):
w.append(i)
nums = itertools.permutations(w) # 它是tuple
p=[]
for x in nums:
p.append(x)
p=[list(x) for x in p]
for i in range(len(p)):
a=[str(x) for x in p[i]]
b.append(int(''.join(a)))
for j in b:
a7=j//10
a6=a7//10
a5=a6//10
a4=a5//10
a3=a4//10
a2=a3//10
if (j%8)==0 and (a7%7)==0 and (a6%6)==0 and (a5%5)==0 and (a4%4)==0 and (a3%3)==0 and (a2%2)==0:
print(j)
答案:38165472
Python Code:
import itertools
w=[]
b=[]
for i in range(1,9):
w.append(i)
nums = itertools.permutations(w) # 它是tuple
p=[]
for x in nums:
p.append(x)
p=[list(x) for x in p]
for i in range(len(p)):
a=[str(x) for x in p[i]]
b.append(int(''.join(a)))
for j in b:
a7=j//10
a6=a7//10
a5=a6//10
a4=a5//10
a3=a4//10
a2=a3//10
if (j%8)==0 and (a7%7)==0 and (a6%6)==0 and (a5%5)==0 and (a4%4)==0 and (a3%3)==0 and (a2%2)==0:
print(j)
答案:38165472
沒有留言:
張貼留言