突然发现结果有异常
[ 5 ] PPDI 8 = 4150
[ 5 ] PPDI 9 = 4151
前面的[ 5]表示是五位数,而抛出的结果却是4位数的。
for val in range(min_val, 10 ** n):
发现在这段代码中,遍历的起始位置是min_val, 导致位数n都要丛min_val开始遍历,
才导致这种结果。
现修改为:
for val in range(10 ** (n - 1), 10 ** n):
结果正确不说,还缩短了运行时间:
Input digit(>2): 8
Start_time = 2017-11-25 13:48:09.852904
2017-11-25 13:48:09.853433 [ 3 ] PPDI 1 = 153 [ 0:00:00.000529 ]
2017-11-25 13:48:09.854518 [ 3 ] PPDI 2 = 370 [ 0:00:00.001614 ]
2017-11-25 13:48:09.854620 [ 3 ] PPDI 3 = 371 [ 0:00:00.001716 ]
2017-11-25 13:48:09.854858 [ 3 ] PPDI 4 = 407 [ 0:00:00.001954 ]
2017-11-25 13:48:09.863425 [ 4 ] PPDI 5 = 1634 [ 0:00:00.010521 ]
2017-11-25 13:48:09.890956 [ 4 ] PPDI 6 = 8208 [ 0:00:00.038052 ]
2017-11-25 13:48:09.895797 [ 4 ] PPDI 7 = 9474 [ 0:00:00.042893 ]
2017-11-25 13:48:10.114127 [ 5 ] PPDI 8 = 54748 [ 0:00:00.261223 ]
2017-11-25 13:48:10.301516 [ 5 ] PPDI 9 = 92727 [ 0:00:00.448612 ]
2017-11-25 13:48:10.303165 [ 5 ] PPDI 10 = 93084 [ 0:00:00.450261 ]
2017-11-25 13:48:12.818301 [ 6 ] PPDI 11 = 548834 [ 0:00:02.965397 ]
2017-11-25 13:48:19.925943 [ 7 ] PPDI 12 = 1741725 [ 0:00:10.073039 ]
2017-11-25 13:48:35.710993 [ 7 ] PPDI 13 = 4210818 [ 0:00:25.858089 ]
2017-11-25 13:49:11.289820 [ 7 ] PPDI 14 = 9800817 [ 0:01:01.436916 ]
2017-11-25 13:49:12.110367 [ 7 ] PPDI 15 = 9926315 [ 0:01:02.257463 ]
2017-11-25 13:50:53.876163 [ 8 ] PPDI 16 = 24678050 [ 0:02:44.023259 ]
2017-11-25 13:50:53.876217 [ 8 ] PPDI 17 = 24678051 [ 0:02:44.023313 ]
2017-11-25 13:58:18.654727 [ 8 ] PPDI 18 = 88593477 [ 0:10:08.801823 ]
Done!
Run Time : 0:11:28.178857