Created
June 1, 2017 23:50
-
-
Save nattybear/389f583c1b1b3185bdcae2f966d0d485 to your computer and use it in GitHub Desktop.
알고스팟 초보용 문제 - 구현
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 func(): | |
# 사용자 입력을 받는다. | |
n = int(input()) | |
# 약수를 저장할 리스트 변수를 생성한다. | |
d = [] | |
# 1부터 입력받은 수까지 반복한다. | |
# 이 때 나눈 나머지가 0인 수 | |
# 즉 나누어 떨어지는 수라면 | |
# d 리스트에 저장한다. | |
for i in range(1, n): | |
if n % i == 0: | |
d.append(i) | |
# 약수의 합이 입력 받은 수보다 크지 않으면 | |
# "not weird"를 출력하고 리턴한다. | |
if sum(d) <= n: | |
print("not weird") | |
return | |
# 약수를 대상으로 반복문을 돈다. | |
# 약수중에서 차례대로 1개씩만 빼고 | |
# 나머지 수의 합을 구한다. | |
# 1개씩만 뺀 나머지의 합 중에서 | |
# 입력 받은 수와 같은 값이 나온다면 | |
# "not weird"를 출력하고 리턴한다. | |
for i in d: | |
t = d.copy() | |
t.remove(i) | |
if sum(t) == n: | |
print("not weird") | |
return | |
# 도중에 한번도 리턴하지 못하고 | |
# 여기까지 왔다면 "weird"를 출력한다. | |
print("weird") | |
c = int(input()) | |
for i in range(c): func() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
시간초과
시간초과
가 난다.