对于某个自然数 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); }