题解 | #完全数计算#
完全数计算
https://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
#include <iostream> using namespace std; int main() { int data; cin >> data; int cnt = 0; for (int i = 0;i <= data;i++) { int yueshuhe = 0; for (int j = 1;j <= i;j++) { if (i % j == 0) //找到小于data值的每一个数i的完全数j { yueshuhe += j; } else { continue; } } if (yueshuhe - i == i) { cnt ++; } } cout << cnt - 1 ; } // 64 位输出请用 printf("%lld")