题解 | #完全数计算#
完全数计算
https://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
#include <iostream>
using namespace std;
bool judge(int n) { //判断n是否是完全数
int a, b;
b = 0;
for (int i = 1; i < n; i++)
if (n % i == 0)
b += i; //求真因子之和
if (b == n) return 1;
else return 0;
}
int main() {
int n, a = 0;
cin >> n;
for (int i = 1; i <= n; i++)
if (judge(i) == 1)
a++;
cout << a << endl;
}
查看10道真题和解析