시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 128 MB 1765 1097 989 64.221%

문제

어떤 숫자 n이 자신을 제외한 모든 약수들의 합과 같으면, 그 수를 완전수라고 한다. 

예를 들어 6은 6 = 1 + 2 + 3 으로 완전수이다.

n이 완전수인지 아닌지 판단해주는 프로그램을 작성하라.

입력

입력은 테스트 케이스마다 한 줄 간격으로 n이 주어진다. (2 < n < 100, 000)

입력의 마지막엔 -1이 주어진다.

출력

테스트케이스 마다 한줄에 하나씩 출력해야 한다.

n이 완전수라면, n을 n이 아닌 약수들의 합으로 나타내어 출력한다(예제 출력 참고).

이 때, 약수들은 오름차순으로 나열해야 한다.

n이 완전수가 아니라면 n is NOT perfect. 를 출력한다.

예제 입력 1

6
12
28
-1

예제 출력 1

6 = 1 + 2 + 3
12 is NOT perfect.
28 = 1 + 2 + 4 + 7 + 14
W3sicHJvYmxlbV9pZCI6Ijk1MDYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWM1N2RcdWMyMThcdWI0ZTRcdWM3NTggXHVkNTY5IiwiZGVzY3JpcHRpb24iOiI8cD5cdWM1YjRcdWI1YTQgXHVjMjJiXHVjNzkwIG5cdWM3NzQgXHVjNzkwXHVjMmUwXHVjNzQ0IFx1YzgxY1x1YzY3OFx1ZDU1YyBcdWJhYThcdWI0ZTAgXHVjNTdkXHVjMjE4XHViNGU0XHVjNzU4IFx1ZDU2OVx1YWNmYyBcdWFjMTlcdWM3M2NcdWJhNzQsJm5ic3A7PHNwYW4gc3R5bGU9XCJsaW5lLWhlaWdodDoxLjZlbVwiPlx1YWRmOCBcdWMyMThcdWI5N2MgXHVjNjQ0XHVjODA0XHVjMjE4XHViNzdjXHVhY2UwIFx1ZDU1Y1x1YjJlNC4mbmJzcDs8XC9zcGFuPjxcL3A+XHJcblxyXG48cD5cdWM2MDhcdWI5N2MgXHViNGU0XHVjNWI0IDZcdWM3NDAmbmJzcDs2ID0gMSArIDIgKyAzIFx1YzczY1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Q7IG4gJmx0OyAxMDAsIDAwMCBmb3IgZWFjaCBjYXNlLiBBIGxpbmUgY29udGFpbmluZyAtMSBkZW5vdGVzIHRoZSBlbmQgb2YgaW5wdXQgYW5kIHNob3VsZCBub3QgYmUgcHJvY2Vzc2VkLjxcL3A+XHJcbiIsIm91dHB1dCI6IjxwPkZvciBlYWNoIGNhc2UsIGRldGVybWluZSB3aGV0aGVyIG9yIG5vdCB0aGUgbnVtYmVyIGlzIFBlcmZlY3QuIElmIHRoZSBudW1iZXIgaXMgUGVyZmVjdCwgZGlzcGxheSB0aGUgc3VtIG9mIGl0cyBwb3NpdGl2ZSBkaXZpc29ycyBsZXNzIHRoYW4gaXRzZWxmLiBUaGUgb3JkZXJpbmcgb2YgdGhlIHRlcm1zIG9mIHRoZSBzdW0gbXVzdCBiZSBpbiBhc2NlbmRpbmcgb3JkZXIuIElmIGEgbnVtYmVyIGlzIG5vdCBQZXJmZWN0LCBwcmludCAmbGRxdW87Jmx0O05VTSZndDsgaXMgTk9UIHBlcmZlY3QuJnJkcXVvOyB3aGVyZSAmbHQ7TlVNJmd0OyBpcyB0aGUgbnVtYmVyIGluIHF1ZXN0aW9uLiBUaGVyZSBtdXN0IGJlIGEgc2luZ2xlIHNwYWNlIGJldHdlZW4gYW55IHdvcmRzLCBzeW1ib2xzLCBvciBudW1iZXJzIGluIGFsbCBvdXRwdXQsIHdpdGggdGhlIGV4Y2VwdGlvbiBvZiB0aGUgcGVyaW9kIGF0IHRoZSBlbmQgb2YgdGhlIHNlbnRlbmNlIHdoZW4gYSBudW1iZXIgaXMgbm90IHBlcmZlY3QuPFwvcD5cclxuIiwiaGludCI6IiIsIm9yaWdpbmFsIjoiMSIsInByb2JsZW1fbGFuZ19jb2RlIjoiXHVjNjAxXHVjNWI0In1d

출처

ACM-ICPC > Regionals > North America > Pacific Northwest Regional > 2013 Pacific Northwest Region Programming Contest F번