完全数(4ms,370k)
iNOC产品部--完全数计算
http://www.nowcoder.com/questionTerminal/7299c12e6abb437c87ad3e712383ff84
#include<iostream> using namespace std; bool isW(int n) { int ans = 1, i = 1; for(i = 2; i * i < n; i++) if(n % i == 0) ans += (i + n / i); ans = i * i == n ? ans += i : ans; return ans == n; } int main() { int n; while(cin >> n) { int res = 0; for(int i = 2; i <= n; i++) if(isW(i)) res++; cout << res << endl; } return 0; }