MapleStory Finger Point

๐Ÿƒ‍โ™‚๏ธBaekjoon/Python

#9506 - python ์•ฝ์ˆ˜๋“ค์˜ ํ•ฉ

HYEJU01 2024. 5. 17. 17:56

 

 ๐Ÿ’ก 

while (True):
    N = int(input())

    cnt = [] #์•ฝ์ˆ˜ ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ธฐ
    sum = 0

    if N == -1:
        break

    cnt.append(N) 

    for i in range(1,N+1):
        if ( N % i == 0):
            cnt.append(i)
            sum += i
    
    if ( (sum-N) != N ) :
        print(cnt[0],end='')
        print(" is NOT perfect.")

    elif ( (sum-N) == N ) :
        print(cnt[0],end='')
        print(" =", cnt[1],end='')

        for i in range(2,len(cnt)-1):
            print(" + " ,end='')    
            print(cnt[i] ,end='')
        print()

 

[์‹คํŒจ] ๋ถ„๋ช… ์ •๋‹ต์€ ๋งž๋Š”๋ฐ ์™œ์ด๋Ÿฌ์ง€ ์‹ถ์—ˆ๋Š”๋ฐ

์ž…๋ ฅ๊ฐ’์„ ํ•œ์ค„์”ฉ ๋ฐ›๊ณ  ๋๋‚ด๋Š” ์ค„ ์•Œ์•˜๋Š”๋ฐ ์—ฐ์†์œผ๋กœ ๋ฐ›๋Š” ๊ฑฐ์˜€๋‹ค.

๊ทธ๋ถ€๋ถ„๋งŒ ๊ณ ์ณ์ฃผ๋‹ˆ ๋ฐ”๋กœ ํ†ต๊ณผ !

 

N = int(input())

cnt = [] #์•ฝ์ˆ˜ ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ธฐ
sum = 0

cnt.append(N) 
for i in range(1,N+1):
    if ( N % i == 0):
        cnt.append(i)
        sum += i
 
if (sum < 0):
    pass
elif ( (sum-N) != N and sum > 0) :
    print(cnt[0],end='')
    print(" is NOT perfect.")
elif ( (sum-N) == N and sum > 0) :
    print(cnt[0],end='')
    print(" =", cnt[1],end='')

    for i in range(2,len(cnt)-1):
        print(" + " ,end='')
        if (i == len(cnt)+1):
            print(cnt[len(cnt)+1])      
        print(cnt[i] ,end='')