[TIOJ] 1823. 幸運碼

題目連結:http://tioj.infor.org/problems/1823
本地建表暴搜亂搞題(?,可以發現若是那個數無法用這些操作變成一,那必然他是會循環的,所以直接開個表看他有沒有重複就好,附個暴搜用的python code:
def modify(x,l):
	if x in l:
		return False
	length = len(str(x))
	l.append(x)
	if x == 1:
		return True
	elif length == 1:
		return modify(x**2,l)
	else:
		temp=0
		for k in str(x):
			temp += int(k)**2
		return modify(temp,l)
count = 0
test = 1
while count <= 10000:
	if modify(test,[]):
		count+=1
		if count in [10,50,100,1000,10000]:
			print(test)
	test+=1
Main Code:
main(){write(1,"44\n320\n694\n6899\n67169\n",22);exit(0);}

留言

這個網誌中的熱門文章

[NPSC] 2009初賽 E. 檸檬汽水傳說

[TIOJ] 1902. 「殿仁.王,不認識,誰啊?」,然後他就死了……

[AtCoder] [經典競程 90 題] 024 - Select +/- One(★2)