题解 | #完全数计算#
完全数计算
http://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
#include <iostream> #include <vector> using namespace std; bool isPer(int n) { int s=0; vector<int> v; for (int i=1;i<n;i++) { if (n%i==0) v.push_back(i); } for(int i=0;i<v.size();i++) { s+=v[i]; } if (s==n) return 1; else return 0; } int main () { int range; while( cin>>range) { int num=0; for (int i=1;i<=range;i++) { if (isPer(i)) num++; } cout<<num<<endl; } }