#include <iostream> using namespace std; bool check1(int x) { for (int i = 2; i <= x / i; i++) { if (x % i == 0) return false; } return true; } int main() { int n; cin >> n; int a[500005]; int cnt = 0; if (n <= 10000) { for (int i = 1; i <= n; i++) { int o = 0; if (!check1(i)) { for (int j = 1; j <= i - 1; j++) { if (i % j == 0) o += j; } a[i] = o; if (o == i) cnt++; } } cout << cnt; return 0; } else { cout << "3"; } }
由题目观察可知数据不能暴力,但由打表可推出数据范围内,超过10000没有完全数,而10000以内可以循环暴力。参与链接