test
来源:互联网 发布:3d游戏编程入门经典 编辑:程序博客网 时间:2024/06/03 18:53
import timet1 = time.time()n = []for i in xrange(317,999): s = "%d" % (i*i) if s.count('0') != 0 \ or s.count('1') > 2 \ or s.count('2') > 2 \ or s.count('3') > 2 \ or s.count('4') > 2 \ or s.count('5') > 2 \ or s.count('6') > 2 \ or s.count('7') > 2 \ or s.count('8') > 2 \ or s.count('9') > 2: continue else: n.append(s)def check(s): if s.count('1') == 2 \ and s.count('2') == 2 \ and s.count('3') == 2 \ and s.count('4') == 2 \ and s.count('5') == 2 \ and s.count('6') == 2 \ and s.count('7') == 2 \ and s.count('8') == 2 \ and s.count('9') == 2: return True else: return Falseresult = []nn = len(n)for i in xrange(nn): for j in xrange(i,nn): for k in xrange(j,nn): if check(n[i]+n[j]+n[k]): result.append(n[i]+n[j]+n[k])for r in result: print rt2 = time.time()print t2-t1