1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
| """ 特殊数学数求法 """ import random import time
pri = [] count = 0
pri1 = [] count1 = 0
pri2 = [] count2 = 0
pri3 = [] count3 = 0
pri4 = [] count4 = 0
pri5 = [] count5 =0
pri6 = [] count6 = 0
pri7 = [] count7 = 0
stime = time.time() for i in range(100,1000): a = i // 100 b = i // 10 % 10 c = i % 10 if i == a ** 3 + b ** 3 + c ** 3 : count += 1 pri.append(i) print(f"有{count}个水仙花数") print(pri, end=' ') print("是水仙花数") etime = time.time() runtime = etime - stime print(f"耗时{runtime}")
stime = time.time() for j in range(1000,10000): a = j // 1000 b = j // 100 % 10 c = j // 10 % 10 d = j % 10 if j == a ** 4 + b ** 4 + c ** 4 +d ** 4: count1 += 1 pri1.append(j) print(f"有{count1}个玫瑰花数") print(pri1, end=' ') print("是玫瑰花数") etime = time.time() runtime = etime - stime print(f"耗时{runtime}")
stime = time.time() for x in range(10000,100000): a = x // 10000 b = x // 1000 % 10 c = x // 100 % 10 d = x // 10 % 10 e = x % 10 if x == a ** 5 + b ** 5 + c ** 5 + d ** 5 + e ** 5: count2 += 1 pri2.append(x) print(f"有{count2}个五角星数") print(pri2, end=' ') print("是五角星数") etime = time.time() runtime = etime - stime print(f"耗时{runtime}")
stime = time.time() for y in range(100000,1000000): a = y // 100000 b = y // 10000 % 10 c = y // 1000 % 10 d = y // 100 % 10 e = y // 10 % 10 f = y % 10 if y == a ** 6 + b ** 6 + c ** 6 + d ** 6 + e ** 6 + f ** 6: count3 += 1 pri3.append(y) print(f"有{count3}个六合数") print(pri3, end=' ') print("是六合数") etime = time.time() runtime = etime - stime print(f"耗时{runtime}")
stime = time.time() for z in range(1000000,10000000): a = z // 1000000 b = z // 100000 % 10 c = z // 10000 % 10 d = z // 1000 % 10 e = z // 100 % 10 f = z // 10 % 10 g = z % 10 if z == a ** 7 + b ** 7 + c ** 7 + d ** 7 + e ** 7 + f ** 7 + g ** 7: count4 +=1 pri4.append(z) print(f"有{count4}个北斗七星数") print(pri4, end=' ') print("是北斗七星数") etime = time.time() runtime = etime - stime print(f"耗时{runtime}")
stime = time.time() for a1 in range(10000000,100000000): a = a1 // 10000000 b = a1 // 1000000 % 10 c = a1 // 100000 % 10 d = a1 // 10000 % 10 e = a1 // 1000 % 10 f = a1 // 100 % 10 g = a1 // 10 % 10 h = a1 % 10 if a1 == a ** 8 + b ** 8 + c ** 8 + d ** 8 + e ** 8 + f ** 8 + g ** 8 + h ** 8: count5 +=1 pri5.append(a1) print(f"有{count5}个八仙数") print(pri5, end=' ') print("是八仙数") etime = time.time() runtime = etime - stime print(f"耗时{runtime}")
stime = time.time() for a2 in range(100000000,1000000000): a = a2 // 100000000 b = a2 // 10000000 % 10 c = a2 // 1000000 % 10 d = a2 // 100000 % 10 e = a2 // 10000 % 10 f = a2 // 1000 % 10 g = a2 // 100 % 10 h = a2 // 10 % 10 b1 = a2 % 10 if a2 == a ** 9 + b ** 9 + c ** 9 + d ** 9 + e ** 9 + f ** 9 + g ** 9 + h ** 9 + b1 ** 9: count6 +=1 pri6.append(a2) print(f"有{count6}个九九重阳数") print(pri6, end=' ') print("是九九重阳数数") etime = time.time() runtime = etime - stime print(f"耗时{runtime}")
stime = time.time() for a3 in range(1000000000,10000000000): a = a3 // 1000000000 b = a3 // 100000000 % 10 c = a3 // 10000000 % 10 d = a3 // 1000000 % 10 e = a3 // 100000 % 10 f = a3 // 10000 % 10 g = a3 // 1000 % 10 h = a3 // 100 % 10 b1 = a3 // 10 % 10 b2 = a3 % 10 if a3 == a ** 10 + b ** 10 + c ** 10 + d ** 10 + e ** 10 + f ** 10 + g ** 10 + h ** 10 + b1 ** 10 + b2 ** 10: count7 +=1 pri7.append(a3) print(f"有{count7}个十全十美数") print(pri7, end=' ') print("是十全十美数") etime = time.time() runtime = etime - stime print(f"耗时{runtime}")
|