#25939: py 有更快的寫法嗎?


810054@gm.flhs.ptc.edu.tw (冬夜)

學校 : 不指定學校
編號 : 156645
來源 : [101.9.131.22]
最後登入時間 :
2021-09-04 15:01:25
a040. 阿姆斯壯數 | From: [101.9.96.169] | 發表日期 : 2021-07-06 10:03

如果你是來抄的,請先了解過程

min,max=map(int,input().split())

w=''

for i in range(min,max+1):

  t=list(str(i))

  n=len(t)

  p=0

  for j in t:

    p+=int(j)**n

  if p==i:

    w+=' '+str(p)

print(w[1:len(w)+1])

if len(w)==0:

  print('none')

    

 
#26237: Re:py 有更快的寫法嗎?


406490150@gms.tku.edu.tw (我是朱朱)

學校 : 國立交通大學
編號 : 139794
來源 : [140.113.236.122]
最後登入時間 :
2022-09-03 11:13:16
a040. 阿姆斯壯數 | From: [114.39.244.168] | 發表日期 : 2021-07-25 23:51

Python有更快的寫法?當然有的!給你參考:

# 法一:list comprehension + sum(map()) (0.4s = 400ms)
ans = [
    k
    for k in map(strrange(*map(intinput().split())))
    if int(k) == sum(map(lambda x:int(x)**len(k), k))
]
print(*ans'none'*(not ans))
 
# 法二:先在自己電腦找好,再查表(18ms)
from bisect import bisect_leftbisect_right
ans = (123456789153370371407163482089474547489272793084)
nm = map(intinput().split())
s = ans[bisect_left(ansn):bisect_right(ansm)]
print(*s'none'*(not s))
 
#28316: Re:py 有更快的寫法嗎?


LittleOrange666 (LittleOrange666)

學校 : 國立科學工業園區實驗高級中學
編號 : 173827
來源 : [140.126.248.232]
最後登入時間 :
2023-06-07 14:09:36
a040. 阿姆斯壯數 | From: [180.177.3.37] | 發表日期 : 2021-11-28 17:15

一行解

print((lambda o:"none" if len(o)==0 else " ".join(o))((lambda l:[str(i) for i in range(int(l[0]),int(l[1])+1) if sum([int(c)**len(str(i)) for c in str(i)])==i])(input().split())))

 
ZeroJudge Forum