问题 E: 完数与盈数
时间限制: 1 Sec 内存限制: 32 MB
献花: 28 解决: 28
[献花][花圈][TK题库]
题目描述
一个数如果恰好等于它的各因子(该数本身除外)子和,如:6=3+2+1,则称其为“完数”;
若因子之和大于该数,则称其为“盈数”。求出2 到60 之间所有“完数”和“盈数”,并以如
下形式输出: E: e1 e2 e3 ……(ei 为完数) G: g1 g2 g3 ……(gi 为盈数)
输入
无
输出
按描述要求输出(注意EG后面的冒号之后有一个空格)。
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
const int MaxN = 60;
void Type(int num, bool &ms, bool & ys)
{
int tmp = 0;
for (int i = 1;i<=num/2; ++i)
{
if (num % i == 0)
{
tmp += i;
}
}
if (tmp == num)
{
ms = true;
ys = false;
return;
}
if (tmp > num)
{
ms = false;
ys = true;
return;
}
ms = false;
ys = false;
return;
}
int main()
{
#ifdef _DEBUG
freopen("data.txt", "r+", stdin);
#endif // _DEBUG
int Man[MaxN], Ying[MaxN];
int M = 0, Y = 0;
bool ms, ys;
for (int i = 2; i <= 60; ++i)
{
Type(i, ms, ys);
if (ms)
{
Man[M++] = i;
continue;
}
if (ys)
Ying[Y++] = i;
}
cout << "E:";
for (int i = 0; i < M; ++i)
{
cout <<" " << Man[i];
}
cout << "\nG:";
for (int i = 0; i < Y; ++i)
{
cout << " " << Ying[i];
}
return 0;
}
/**************************************************************
Problem: 1997
User: Sharwen
Language: C++
Result: 升仙
Time:0 ms
Memory:0 kb
****************************************************************/