## 문제
BOJ 4673 셀프 넘버
## solution
self number 함수를 먼저 만들고, 1~10000까지 체크해서 생성자가 있는 숫자를 지워보자. 숫자 양이 많아서 제한에 걸릴지는 모르겠다.
## CODE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self_number(n): | |
tmp_list = list(str(n)) | |
tmp_list2 = list(map(int,tmp_list)) | |
return sum(tmp_list2) + n | |
def main(): | |
number_list = [] | |
for k in range(1,10001): | |
number_list += [self_number(k)] | |
numbers = list(set(number_list)) | |
for k in range(1,10001): | |
if k not in numbers: | |
print(k) | |
return None | |
if __name__=='__main__': | |
main() |
크게 어려운것 없이 풀었다. set으로 중복된걸 줄이는 과정이 속도향상에 크게 의미가 있는지는 잘 모르겠다.
중복된걸 줄이면 596ms에서 568ms로 시간이 줄어든다. 얼마나 의미가 있는지는 더 공부해봐야 알것 같다.
0 댓글