题解 | #完全数计算#
完全数计算
http://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
对于某个自然数 i*i<=n即可,不用i<n。用除法不用取余
#include<stdio.h> int main(){ int number; scanf("%d", &number); int count = 0; for(int i=1; i<=number; i++){ if(i==1) continue; int all = 1; for(int j=2; j*j<=i; j++){ int q = i/j; if(q*j==i){ if(q!=j) all = all+q+j; else all = all+q; } } if(all == i) count++; } printf("%d\n", count); }