Home > Back-end > For the bosses to help me take a look at this perfect number (an integer does not include all factor
For the bosses to help me take a look at this perfect number (an integer does not include all factor
Time:09-29
CodePudding user response:
The leakage part of factor
bool isPerect (int n) { Int m; int sum=0; For (m=1; M<=n/2; + + m) {//cycle to half n only because of you, more than half of n factor missed the accumulative If (n % m==0) { The sum +=m; If (m! Sum=n/2) +=n/m;//missed the factor here } } If (sum==n) return true; return false; }
CodePudding user response:
Rectify the Int sum=1; For (m=2; M<=n/2; 2 + + m)//start cycle, otherwise==0 n % 1, sum +=n/m have a problem, so take out 1 cycle