문제 링크입니다: https://www.acmicpc.net/problem/6975
6975번: Deficient, Perfect, and Abundant
Write a program that repeatedly reads a positive integer, determines if the integer is deficient, perfect, or abundant, and outputs the number along with its classification. A positive integer, n, is said to be perfect if the sum of its proper diviso
www.acmicpc.net
간단한 구현 문제였습니다.
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
#include <iostream> | |
using namespace std; | |
void getResult(int num) | |
{ | |
int sum = 0; | |
for (int i = 1; i < num; i++) | |
{ | |
if (num%i == 0) | |
{ | |
sum += i; | |
} | |
} | |
cout << num; | |
if (sum < num) | |
{ | |
cout << " is a deficient number.\n"; | |
} | |
else if (sum == num) | |
{ | |
cout << " is a perfect number.\n"; | |
} | |
else | |
{ | |
cout << " is an abundant number.\n"; | |
} | |
cout << "\n"; | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
for (int n = 0; n < N; n++) | |
{ | |
int num; | |
cin >> num; | |
getResult(num); | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 7510번 고급 수학 (0) | 2021.06.05 |
---|---|
백준 7015번 Millennium (0) | 2021.06.04 |
백준 6794번 What is n, Daddy? (1) | 2021.06.04 |
백준 6780번 Sumac Sequences (0) | 2021.06.04 |
백준 6779번 Who Has Seen The Wind (0) | 2021.06.04 |