华为机试-完全数计算(HJ56)
iNOC产品部--完全数计算
https://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84?tpId=37&&tqId=21279&rp=1&ru=/ta/huawei&qru=/ta/huawei/question-ranking
纯C
#include <stdlib.h> #include <stdio.h> int count(int n) { if(n<=0 || n>=500000) return -1; int ret=0; for(int i=5; i<n; ++i) { int sum=0; for(int j=1; j<=(i/2); ++j) { if((i%j) == 0) sum+=j; } if(sum == i) ret++; } return ret; } int main() { int out, n; while(scanf("%d", &n) != EOF) { out = count(n); if(out>=0) printf("%d\n", out); else return -1; } return 0; }