Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Last active November 5, 2019 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinglunliao/5d98f895303d8998c085 to your computer and use it in GitHub Desktop.
Save pinglunliao/5d98f895303d8998c085 to your computer and use it in GitHub Desktop.
d010: 盈數、虧數和完全數 FYI: https://yunlinsong.blogspot.com/2016/01/blog-post_44.html
#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