You are viewing a single comment's thread. Return to all comments →
You can optimize that one step to the following... to avoid correction for doubble addition, when input number is an exact square.
public int divisorSum(int n){ int sum = 0;int i; for( i = 1; i <(int)Math.sqrt(n); i++) { if(n%i==0){ sum = sum + i + n/i; } } if(i*i == n){ sum = sum+i; } return sum; }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 19: Interfaces
You are viewing a single comment's thread. Return to all comments →
You can optimize that one step to the following... to avoid correction for doubble addition, when input number is an exact square.