|
发表于 2017-8-13 12:00:58
|
显示全部楼层
- from time import time
- start = time()
- def isPandingital(n):
- i =1
- str_1 = ''
- tag = True
- while i<10:
- str_1 = str_1+str(n*i)
- i = i + 1
- if '0' not in str_1:
- if len(set(str_1))==9 and len(str_1)==9:
- return True
- break
- return False
- def getPandingital(n):
- i = 1
- str_1 = ''
- tag = True
- while i < 10:
- str_1 = str_1+str(n * i)
- i = i + 1
- if '0' not in str_1:
- if len(set(str_1)) == 9 and len(str_1) == 9:
- return int(str_1)
- num = 10000 #n需要大于1,所以需要两个数组合,num不会超过4位数,为保险,可以取num = 100000
- while num > 0:
- if not isPandingital(num):
- num -=1
- else:
- print(num)
- print(getPandingital(num))
- break
- print("Program running cost %4f secs!" % (time() - start))
复制代码
9327
932718654
Program running cost 0.005000 secs! |
|