Last active
November 5, 2019 08:22
-
-
Save pinglunliao/5d98f895303d8998c085 to your computer and use it in GitHub Desktop.
d010: 盈數、虧數和完全數 FYI: https://yunlinsong.blogspot.com/2016/01/blog-post_44.html
This file contains 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> | |
#include <cmath> | |
using namespace std; | |
void prtMsg(const int &s, const int &n) | |
{ | |
if( s == n ) | |
cout << "完全數"; | |
else if( s > n ) | |
cout << "盈數"; | |
else | |
cout << "虧數"; | |
cout << endl; | |
} | |
int main() | |
{ | |
int n; | |
while( cin >> n ) | |
{ | |
int s = 0; | |
for( int i = 1; i <= n/2; i++ ) | |
{ | |
if( n % i == 0 ) | |
s += i; | |
} | |
prtMsg(s, n); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment